function import_gedcom_file($gedcom_id, $path, $filename)
{
    // Read the file in blocks of roughly 64K.  Ensure that each block
    // contains complete gedcom records.  This will ensure we don’t split
    // multi-byte characters, as well as simplifying the code to import
    // each block.
    $file_data = '';
    $fp = fopen($path, 'rb');
    WT_DB::exec("START TRANSACTION");
    WT_DB::prepare("DELETE FROM `##gedcom_chunk` WHERE gedcom_id=?")->execute(array($gedcom_id));
    while (!feof($fp)) {
        $file_data .= fread($fp, 65536);
        // There is no strrpos() function that searches for substrings :-(
        for ($pos = strlen($file_data) - 1; $pos > 0; --$pos) {
            if ($file_data[$pos] == '0' && ($file_data[$pos - 1] == "\n" || $file_data[$pos - 1] == "\r")) {
                // We’ve found the last record boundary in this chunk of data
                break;
            }
        }
        if ($pos) {
            WT_DB::prepare("INSERT INTO `##gedcom_chunk` (gedcom_id, chunk_data) VALUES (?, ?)")->execute(array($gedcom_id, substr($file_data, 0, $pos)));
            $file_data = substr($file_data, $pos);
        }
    }
    WT_DB::prepare("INSERT INTO `##gedcom_chunk` (gedcom_id, chunk_data) VALUES (?, ?)")->execute(array($gedcom_id, $file_data));
    set_gedcom_setting($gedcom_id, 'gedcom_filename', $filename);
    WT_DB::exec("COMMIT");
    fclose($fp);
}
Exemple #2
0
 private function loadIndividuals()
 {
     $sql = "SELECT DISTINCT i_id AS xref, i_file AS gedcom_id, i_gedcom AS gedcom" . " FROM `##individuals`" . " JOIN `##name` ON (i_id=n_id AND i_file=n_file)" . " WHERE n_file=?" . " AND n_type!=?" . " AND (n_surn=? OR n_surname=?";
     $args = array(WT_GED_ID, '_MARNM', $this->surname, $this->surname);
     if ($this->soundex_std) {
         $sdx = WT_Soundex::soundex_std($this->surname);
         if ($sdx) {
             foreach (explode(':', $sdx) as $value) {
                 $sql .= " OR n_soundex_surn_std LIKE CONCAT('%', ?, '%')";
                 $args[] = $value;
             }
         }
     }
     if ($this->soundex_dm) {
         $sdx = WT_Soundex::soundex_dm($this->surname);
         if ($sdx) {
             foreach (explode(':', $sdx) as $value) {
                 $sql .= " OR n_soundex_surn_dm LIKE CONCAT('%', ?, '%')";
                 $args[] = $value;
             }
         }
     }
     $sql .= ')';
     $rows = WT_DB::prepare($sql)->execute($args)->fetchAll();
     $this->individuals = array();
     foreach ($rows as $row) {
         $this->individuals[] = WT_Individual::getInstance($row->xref, $row->gedcom_id, $row->gedcom);
     }
     // Sort by birth date, oldest first
     usort($this->individuals, array('WT_Individual', 'CompareBirtDate'));
 }
Exemple #3
0
 protected static function fetchGedcomRecord($xref, $gedcom_id)
 {
     static $statement = null;
     if ($statement === null) {
         $statement = WT_DB::prepare("SELECT m_gedcom FROM `##media` WHERE m_id=? AND m_file=?");
     }
     return $statement->execute(array($xref, $gedcom_id))->fetchOne();
 }
Exemple #4
0
 protected static function fetchGedcomRecord($xref, $gedcom_id)
 {
     static $statement = null;
     if ($statement === null) {
         $statement = WT_DB::prepare("SELECT o_gedcom FROM `##other` WHERE o_id=? AND o_file=? AND o_type='NOTE'");
     }
     return $statement->execute(array($xref, $gedcom_id))->fetchOne();
 }
Exemple #5
0
 /**
  * Set the site’s configuration settings.
  *
  * @param string          $setting_name
  * @param string|int|bool $setting_value
  *
  * @return void
  */
 public static function setPreference($setting_name, $setting_value)
 {
     // Only need to update the database if the setting has actually changed.
     if (self::getPreference($setting_name) != $setting_value) {
         WT_DB::prepare("REPLACE INTO `##site_setting` (setting_name, setting_value) VALUES (?, LEFT(?, 255))")->execute(array($setting_name, $setting_value));
         self::$setting[$setting_name] = $setting_value;
         Log::addConfigurationLog('Site setting "' . $setting_name . '" set to "' . $setting_value . '"');
     }
 }
Exemple #6
0
 public function getBlock($block_id, $template = true, $cfg = null)
 {
     global $ctype, $SHOW_COUNTER;
     $count_placement = get_block_setting($block_id, 'count_placement', 'before');
     $num = (int) get_block_setting($block_id, 'num', 10);
     $block = get_block_setting($block_id, 'block', false);
     if ($cfg) {
         foreach (array('count_placement', 'num', 'block') as $name) {
             if (array_key_exists($name, $cfg)) {
                 ${$name} = $cfg[$name];
             }
         }
     }
     $id = $this->getName() . $block_id;
     $class = $this->getName() . '_block';
     if ($ctype == 'gedcom' && WT_USER_GEDCOM_ADMIN || $ctype == 'user' && WT_USER_ID) {
         $title = '<i class="icon-admin" title="' . WT_I18N::translate('Configure') . '" onclick="modalDialog(\'block_edit.php?block_id=' . $block_id . '\', \'' . $this->getTitle() . '\');"></i>';
     } else {
         $title = '';
     }
     $title .= $this->getTitle();
     $content = "";
     // load the lines from the file
     $top10 = WT_DB::prepare("SELECT page_parameter, page_count" . " FROM `##hit_counter`" . " WHERE gedcom_id=? AND page_name IN ('individual.php','family.php','source.php','repo.php','note.php','mediaviewer.php')" . " ORDER BY page_count DESC LIMIT " . $num)->execute(array(WT_GED_ID))->FetchAssoc();
     if ($block) {
         $content .= "<table width=\"90%\">";
     } else {
         $content .= "<table>";
     }
     foreach ($top10 as $id => $count) {
         $record = WT_GedcomRecord::getInstance($id);
         if ($record && $record->canShow()) {
             $content .= '<tr valign="top">';
             if ($count_placement == 'before') {
                 $content .= '<td dir="ltr" align="right">[' . $count . ']</td>';
             }
             $content .= '<td class="name2" ><a href="' . $record->getHtmlUrl() . '">' . $record->getFullName() . '</a></td>';
             if ($count_placement == 'after') {
                 $content .= '<td dir="ltr" align="right">[' . $count . ']</td>';
             }
             $content .= '</tr>';
         }
     }
     $content .= "</table>";
     if ($template) {
         if ($block) {
             require WT_THEME_DIR . 'templates/block_small_temp.php';
         } else {
             require WT_THEME_DIR . 'templates/block_main_temp.php';
         }
     } else {
         return $content;
     }
 }
Exemple #7
0
 /**
  * Execute a query
  *
  * @param array $bind_variables
  *
  * @return WT_DBStatement
  * @throws Exception
  */
 public function execute($bind_variables = array())
 {
     if ($this->executed) {
         throw new Exception('WT_DBStatement::execute() called twice.');
     }
     // Turn booleans into integers.  Otherwise MySQL’s strict mode can get upset.
     foreach ($bind_variables as &$bind_variable) {
         if ($bind_variable === false) {
             // Otherwise true=>'1' and false=>''
             $bind_variable = 0;
         }
     }
     $start = microtime(true);
     $this->pdo_statement->execute($bind_variables);
     $end = microtime(true);
     // If it was a SELECT statement, we cannot run it again.
     $this->executed = strpos($this->pdo_statement->queryString, 'SELECT') === 0;
     WT_DB::logQuery($this->pdo_statement->queryString, $this->pdo_statement->rowCount(), $end - $start, $bind_variables);
     return $this;
 }
Exemple #8
0
 public static function preference($setting_name, $setting_value = null)
 {
     // There are lots of settings, and we need to fetch lots of them on every page
     // so it is quicker to fetch them all in one go.
     if (self::$setting === null) {
         self::$setting = WT_DB::prepare("SELECT SQL_CACHE setting_name, setting_value FROM `##site_setting`")->fetchAssoc();
     }
     // If $setting_value is null, then GET the setting
     if ($setting_value === null) {
         // If parameter two is not specified, GET the setting
         if (!array_key_exists($setting_name, self::$setting)) {
             self::$setting[$setting_name] = null;
         }
         return self::$setting[$setting_name];
     } else {
         // If parameter two is specified, then SET the setting
         if (self::preference($setting_name) != $setting_value) {
             // Audit log of changes
             Log::addConfigurationLog('Site setting "' . $setting_name . '" set to "' . $setting_value . '"');
         }
         WT_DB::prepare("REPLACE INTO `##site_setting` (setting_name, setting_value) VALUES (?, LEFT(?, 255))")->execute(array($setting_name, $setting_value));
         self::$setting[$setting_name] = $setting_value;
     }
 }
Exemple #9
0
 /**
  * Fetch a list of individuals with specified names
  *
  * To search for unknown names, use $surn="@N.N.", $salpha="@" or $galpha="@"
  * To search for names with no surnames, use $salpha=","
  *
  * @param string $surn   if set, only fetch people with this surname
  * @param string $salpha if set, only fetch surnames starting with this letter
  * @param string $galpha if set, only fetch given names starting with this letter
  * @param bool   $marnm  if set, include married names
  * @param bool   $fams   if set, only fetch individuals with FAMS records
  * @param int    $ged_id if set, only fetch individuals from this gedcom
  *
  * @return WT_Individual[]
  */
 public static function individuals($surn, $salpha, $galpha, $marnm, $fams, $ged_id)
 {
     $sql = "SELECT i_id AS xref, i_file AS gedcom_id, i_gedcom AS gedcom, n_full " . "FROM `##individuals` " . "JOIN `##name` ON (n_id=i_id AND n_file=i_file) " . ($fams ? "JOIN `##link` ON (n_id=l_from AND n_file=l_file AND l_type='FAMS') " : "") . "WHERE n_file={$ged_id} " . ($marnm ? "" : "AND n_type!='_MARNM'");
     if ($surn) {
         $sql .= " AND n_surn COLLATE '" . WT_I18N::$collation . "'=" . WT_DB::quote($surn);
     } elseif ($salpha == ',') {
         $sql .= " AND n_surn=''";
     } elseif ($salpha == '@') {
         $sql .= " AND n_surn='@N.N.'";
     } elseif ($salpha) {
         $sql .= " AND " . self::_getInitialSql('n_surn', $salpha);
     } else {
         // All surnames
         $sql .= " AND n_surn NOT IN ('', '@N.N.')";
     }
     if ($galpha) {
         $sql .= " AND " . self::_getInitialSql('n_givn', $galpha);
     }
     $sql .= " ORDER BY CASE n_surn WHEN '@N.N.' THEN 1 ELSE 0 END, n_surn COLLATE '" . WT_I18N::$collation . "', CASE n_givn WHEN '@P.N.' THEN 1 ELSE 0 END, n_givn COLLATE '" . WT_I18N::$collation . "'";
     $list = array();
     $rows = WT_DB::prepare($sql)->fetchAll();
     foreach ($rows as $row) {
         $person = WT_Individual::getInstance($row->xref, $row->gedcom_id, $row->gedcom);
         // The name from the database may be private - check the filtered list...
         foreach ($person->getAllNames() as $n => $name) {
             if ($name['fullNN'] == $row->n_full) {
                 $person->setPrimaryName($n);
                 // We need to clone $person, as we may have multiple references to the
                 // same person in this list, and the "primary name" would otherwise
                 // be shared amongst all of them.
                 $list[] = clone $person;
                 break;
             }
         }
     }
     return $list;
 }
Exemple #10
0
 public function getSignificantIndividual()
 {
     static $individual;
     // Only query the DB once.
     if (!$individual && WT_USER_ROOT_ID) {
         $individual = WT_Individual::getInstance(WT_USER_ROOT_ID);
     }
     if (!$individual && WT_USER_GEDCOM_ID) {
         $individual = WT_Individual::getInstance(WT_USER_GEDCOM_ID);
     }
     if (!$individual) {
         $individual = WT_Individual::getInstance(get_gedcom_setting(WT_GED_ID, 'PEDIGREE_ROOT_ID'));
     }
     if (!$individual) {
         $individual = WT_Individual::getInstance(WT_DB::prepare("SELECT MIN(i_id) FROM `##individuals` WHERE i_file=?")->execute(array(WT_GED_ID))->fetchOne());
     }
     if (!$individual) {
         // always return a record
         $individual = new WT_Individual('I', '0 @I@ INDI', null, WT_GED_ID);
     }
     return $individual;
 }
    echo $module->getDescription();
    ?>
</td>
						<td><input type="text" size="3" value="<?php 
    echo $order;
    ?>
" name="sidebarorder-<?php 
    echo $module->getName();
    ?>
"></td>
						<td>
							<table class="modules_table2">
								<?php 
    foreach (WT_Tree::getAll() as $tree) {
        $varname = 'sidebaraccess-' . $module_name . '-' . $tree->tree_id;
        $access_level = WT_DB::prepare("SELECT access_level FROM `##module_privacy` WHERE gedcom_id=? AND module_name=? AND component='sidebar'")->execute(array($tree->tree_id, $module_name))->fetchOne();
        if ($access_level === null) {
            $access_level = $module->defaultAccessLevel();
        }
        echo '<tr><td>', $tree->tree_title_html, '</td><td>';
        echo edit_field_access_level($varname, $access_level);
    }
    ?>
							</table>
						</td>
					</tr>
				<?php 
    $order++;
}
?>
			</tbody>
Exemple #12
0
function update_favorites($xref_from, $xref_to, $ged_id = WT_GED_ID)
{
    return WT_DB::prepare("UPDATE `##favorite` SET xref=? WHERE xref=? AND gedcom_id=?")->execute(array($xref_to, $xref_from, $ged_id))->rowCount();
}
Exemple #13
0
// It shouldn't do anything that might take more than a few
// seconds, for systems with low timeout values.
//
// webtrees: Web based Family History software
// Copyright (C) 2014 Greg Roach
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
if (!defined('WT_WEBTREES')) {
    header('HTTP/1.0 403 Forbidden');
    exit;
}
// Create all of the tables needed for this module
try {
    WT_DB::exec("ALTER TABLE `##placelocation` ADD (" . " pl_media      VARCHAR(60)     NULL," . " sv_long       FLOAT           NOT NULL DEFAULT 0," . " sv_lati       FLOAT           NOT NULL DEFAULT 0," . " sv_bearing    FLOAT           NOT NULL DEFAULT 0," . " sv_elevation  FLOAT           NOT NULL DEFAULT 0," . " sv_zoom       FLOAT           NOT NULL DEFAULT 1" . ")");
} catch (PDOException $ex) {
    // Already done this?
}
// Update the version to indicate success
WT_Site::preference($schema_name, $next_version);
Exemple #14
0
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
if (!defined('WT_WEBTREES')) {
    header('HTTP/1.0 403 Forbidden');
    exit;
}
// Create tables, if not already present
try {
    WT_DB::updateSchema(WT_MODULES_DIR, 'user_blog/db_schema/', 'NB_SCHEMA_VERSION', 3);
} catch (PDOException $ex) {
    // The schema update scripts should never fail.  If they do, there is no clean recovery.
    die($ex);
}
class user_blog_WT_Module extends WT_Module implements WT_Module_Block
{
    // Extend class WT_Module
    public function getTitle()
    {
        return WT_I18N::translate('Journal');
    }
    // Extend class WT_Module
    public function getDescription()
    {
        return WT_I18N::translate('A private area to record notes or keep a journal.');
Exemple #15
0
 public function ajaxRequest()
 {
     global $SEARCH_SPIDER;
     // Search engines should not make AJAX requests
     if ($SEARCH_SPIDER) {
         header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden');
         exit;
     }
     // Initialise tabs
     $tab = WT_Filter::get('module');
     // A request for a non-existant tab?
     if (array_key_exists($tab, $this->tabs)) {
         $mod = $this->tabs[$tab];
     } else {
         header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
         exit;
     }
     header("Content-Type: text/html; charset=UTF-8");
     // AJAX calls do not have the meta tag headers and need this set
     header("X-Robots-Tag: noindex,follow");
     // AJAX pages should not show up in search results, any links can be followed though
     Zend_Session::writeClose();
     echo $mod->getTabContent();
     if (WT_DEBUG_SQL) {
         echo WT_DB::getQueryLog();
     }
 }
                    case 'desc':
                        $ORDER_BY .= 1 + $order[$i]['column'] . ' DESC ';
                        break;
                }
            }
        } else {
            $ORDER_BY = '1 ASC';
        }
        // This becomes a JSON list, not array, so need to fetch with numeric keys.
        $data = WT_DB::prepare($SELECT1 . $WHERE . $ORDER_BY . $LIMIT)->execute($args)->fetchAll(PDO::FETCH_NUM);
        foreach ($data as &$datum) {
            $datum[2] = WT_Filter::escapeHtml($datum[2]);
        }
        // Total filtered/unfiltered rows
        $recordsFiltered = WT_DB::prepare("SELECT FOUND_ROWS()")->fetchColumn();
        $recordsTotal = WT_DB::prepare($SELECT2 . $WHERE)->execute($args)->fetchColumn();
        header('Content-type: application/json');
        echo json_encode(array('sEcho' => WT_Filter::getInteger('sEcho'), 'recordsTotal' => $recordsTotal, 'recordsFiltered' => $recordsFiltered, 'data' => $data));
        exit;
}
$controller->pageHeader()->addExternalJavascript(WT_JQUERY_DATATABLES_URL)->addInlineJavascript('
		jQuery("#log_list").dataTable( {
			dom: \'<"H"pf<"dt-clear">irl>t<"F"pl>\',
			processing: true,
			serverSide: true,
			ajax: "' . WT_SERVER_NAME . WT_SCRIPT_PATH . WT_SCRIPT_NAME . '?action=load_json&from=' . $from . '&to=' . $to . '&type=' . $type . '&text=' . rawurlencode($text) . '&ip=' . rawurlencode($ip) . '&user='******'&gedc=' . rawurlencode($gedc) . '",
			' . WT_I18N::datatablesI18N(array(10, 20, 50, 100, 500, 1000, -1)) . ',
			jQueryUI: true,
			autoWidth: false,
			sorting: [[ 0, "desc" ]],
			pageLength: ' . Auth::user()->getSetting('admin_site_log_page_size', 20) . ',
Exemple #17
0
 /**
  * Count the number of media objects that have been edited this month
  *
  * @param int $ged_id
  *
  * @return int
  */
 public static function countObjeChangesMonth($ged_id)
 {
     return WT_DB::prepare("SELECT count(change_id) FROM `##change`" . " JOIN `##media` ON (gedcom_id=m_file AND m_id=xref)" . " WHERE status='accepted' AND MONTH(change_time)= MONTH(NOW()) AND gedcom_id=?")->execute(array($ged_id))->fetchOne();
 }
Exemple #18
0
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
if (!defined('WT_WEBTREES')) {
    header('HTTP/1.0 403 Forbidden');
    exit;
}
// Add new columns
try {
    WT_DB::exec("ALTER TABLE `##news`" . " ADD user_id INTEGER NULL AFTER n_id," . " ADD gedcom_id INTEGER NULL AFTER user_id," . " ADD updated TIMESTAMP ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP," . " ADD KEY news_ix1 (user_id, updated)," . " ADD KEY news_ix2 (gedcom_id, updated)");
} catch (PDOException $ex) {
    // Already updated?
}
// Migrate data from the old columns to the new ones
try {
    WT_DB::exec("UPDATE `##news` n" . " LEFT JOIN `##gedcom` g ON (n.n_username=g.gedcom_name)" . " LEFT JOIN `##user` u ON (n.n_username=u.user_name)" . " SET n.gedcom_id=g.gedcom_id, n.user_id=u.user_id, updated=FROM_UNIXTIME(n_date)");
} catch (PDOException $ex) {
    // Already updated?
}
// Delete orphaned rows
try {
    WT_DB::exec("DELETE FROM `##news` WHERE user_id IS NULL AND gedcom_id IS NULL");
} catch (PDOException $ex) {
    // Already updated?
}
// Delete/rename old columns
try {
    WT_DB::exec("ALTER TABLE `##news`" . " DROP n_username, DROP n_date," . " CHANGE n_id news_id INTEGER NOT NULL AUTO_INCREMENT," . " CHANGE n_title subject VARCHAR(255) COLLATE utf8_unicode_ci," . " CHANGE n_text body TEXT COLLATE utf8_unicode_ci");
} catch (PDOException $ex) {
    // Already updated?
}
// Update the version to indicate success
WT_Site::preference($schema_name, $next_version);
Exemple #19
0
 function advancedSearch($justSql = false, $table = "individuals", $prefix = "i")
 {
     $this->myindilist = array();
     $fct = count($this->fields);
     if ($fct == 0) {
         return;
     }
     // Dynamic SQL query, plus bind variables
     $sql = "SELECT DISTINCT ind.i_id AS xref, ind.i_file AS gedcom_id, ind.i_gedcom AS gedcom FROM `##individuals` ind";
     $bind = array();
     // Join the following tables
     $father_name = false;
     $mother_name = false;
     $spouse_family = false;
     $indi_name = false;
     $indi_date = false;
     $fam_date = false;
     $indi_plac = false;
     $fam_plac = false;
     foreach ($this->fields as $n => $field) {
         if ($this->values[$n]) {
             if (substr($field, 0, 14) == 'FAMC:HUSB:NAME') {
                 $father_name = true;
             } elseif (substr($field, 0, 14) == 'FAMC:WIFE:NAME') {
                 $mother_name = true;
             } elseif (substr($field, 0, 4) == 'NAME') {
                 $indi_name = true;
             } elseif (strpos($field, ':DATE') !== false) {
                 if (substr($field, 0, 4) == 'FAMS') {
                     $fam_date = true;
                     $spouse_family = true;
                 } else {
                     $indi_date = true;
                 }
             } elseif (strpos($field, ':PLAC') !== false) {
                 if (substr($field, 0, 4) == 'FAMS') {
                     $fam_plac = true;
                     $spouse_family = true;
                 } else {
                     $indi_plac = true;
                 }
             }
         }
     }
     if ($father_name || $mother_name) {
         $sql .= " JOIN `##link`   l_1 ON (l_1.l_file=ind.i_file AND l_1.l_from=ind.i_id AND l_1.l_type='FAMC')";
     }
     if ($father_name) {
         $sql .= " JOIN `##link`   l_2 ON (l_2.l_file=ind.i_file AND l_2.l_from=l_1.l_to AND l_2.l_type='HUSB')";
         $sql .= " JOIN `##name`   f_n ON (f_n.n_file=ind.i_file AND f_n.n_id  =l_2.l_to)";
     }
     if ($mother_name) {
         $sql .= " JOIN `##link`   l_3 ON (l_3.l_file=ind.i_file AND l_3.l_from=l_1.l_to AND l_3.l_type='WIFE')";
         $sql .= " JOIN `##name`   m_n ON (m_n.n_file=ind.i_file AND m_n.n_id  =l_3.l_to)";
     }
     if ($spouse_family) {
         $sql .= " JOIN `##link`     l_4 ON (l_4.l_file=ind.i_file AND l_4.l_from=ind.i_id AND l_4.l_type='FAMS')";
         $sql .= " JOIN `##families` fam ON (fam.f_file=ind.i_file AND fam.f_id  =l_4.l_to)";
     }
     if ($indi_name) {
         $sql .= " JOIN `##name`   i_n ON (i_n.n_file=ind.i_file AND i_n.n_id=ind.i_id)";
     }
     if ($indi_date) {
         $sql .= " JOIN `##dates`  i_d ON (i_d.d_file=ind.i_file AND i_d.d_gid=ind.i_id)";
     }
     if ($fam_date) {
         $sql .= " JOIN `##dates`  f_d ON (f_d.d_file=ind.i_file AND f_d.d_gid=fam.f_id)";
     }
     if ($indi_plac) {
         $sql .= " JOIN `##placelinks`   i_pl ON (i_pl.pl_file=ind.i_file AND i_pl.pl_gid =ind.i_id)";
         $sql .= " JOIN (" . "SELECT CONCAT_WS(', ', p1.p_place, p2.p_place, p3.p_place, p4.p_place, p5.p_place, p6.p_place, p7.p_place, p8.p_place, p9.p_place) AS place, p1.p_id AS id, p1.p_file AS file" . " FROM      `##places` AS p1" . " LEFT JOIN `##places` AS p2 ON (p1.p_parent_id=p2.p_id)" . " LEFT JOIN `##places` AS p3 ON (p2.p_parent_id=p3.p_id)" . " LEFT JOIN `##places` AS p4 ON (p3.p_parent_id=p4.p_id)" . " LEFT JOIN `##places` AS p5 ON (p4.p_parent_id=p5.p_id)" . " LEFT JOIN `##places` AS p6 ON (p5.p_parent_id=p6.p_id)" . " LEFT JOIN `##places` AS p7 ON (p6.p_parent_id=p7.p_id)" . " LEFT JOIN `##places` AS p8 ON (p7.p_parent_id=p8.p_id)" . " LEFT JOIN `##places` AS p9 ON (p8.p_parent_id=p9.p_id)" . ") AS i_p ON (i_p.file  =ind.i_file AND i_pl.pl_p_id= i_p.id)";
     }
     if ($fam_plac) {
         $sql .= " JOIN `##placelinks`   f_pl ON (f_pl.pl_file=ind.i_file AND f_pl.pl_gid =fam.f_id)";
         $sql .= " JOIN (" . "SELECT CONCAT_WS(', ', p1.p_place, p2.p_place, p3.p_place, p4.p_place, p5.p_place, p6.p_place, p7.p_place, p8.p_place, p9.p_place) AS place, p1.p_id AS id, p1.p_file AS file" . " FROM      `##places` AS p1" . " LEFT JOIN `##places` AS p2 ON (p1.p_parent_id=p2.p_id)" . " LEFT JOIN `##places` AS p3 ON (p2.p_parent_id=p3.p_id)" . " LEFT JOIN `##places` AS p4 ON (p3.p_parent_id=p4.p_id)" . " LEFT JOIN `##places` AS p5 ON (p4.p_parent_id=p5.p_id)" . " LEFT JOIN `##places` AS p6 ON (p5.p_parent_id=p6.p_id)" . " LEFT JOIN `##places` AS p7 ON (p6.p_parent_id=p7.p_id)" . " LEFT JOIN `##places` AS p8 ON (p7.p_parent_id=p8.p_id)" . " LEFT JOIN `##places` AS p9 ON (p8.p_parent_id=p9.p_id)" . ") AS f_p ON (f_p.file  =ind.i_file AND f_pl.pl_p_id= f_p.id)";
     }
     // Add the where clause
     $sql .= " WHERE ind.i_file=?";
     $bind[] = WT_GED_ID;
     for ($i = 0; $i < $fct; $i++) {
         $field = $this->fields[$i];
         $value = $this->values[$i];
         if ($value === '') {
             continue;
         }
         $parts = preg_split("/:/", $field . '::::');
         if ($parts[0] == 'NAME') {
             // NAME:*
             switch ($parts[1]) {
                 case 'GIVN':
                     switch ($parts[2]) {
                         case 'EXACT':
                             $sql .= " AND i_n.n_givn=?";
                             $bind[] = $value;
                             break;
                         case 'BEGINS':
                             $sql .= " AND i_n.n_givn LIKE CONCAT(?, '%')";
                             $bind[] = $value;
                             break;
                         case 'CONTAINS':
                             $sql .= " AND i_n.n_givn LIKE CONCAT('%', ?, '%')";
                             $bind[] = $value;
                             break;
                         case 'SDX_STD':
                             $sdx = WT_Soundex::soundex_std($value);
                             if ($sdx) {
                                 $sdx = explode(':', $sdx);
                                 foreach ($sdx as $k => $v) {
                                     $sdx[$k] = "i_n.n_soundex_givn_std LIKE CONCAT('%', ?, '%')";
                                     $bind[] = $v;
                                 }
                                 $sql .= ' AND (' . implode(' OR ', $sdx) . ')';
                             } else {
                                 // No phonetic content?  Use a substring match
                                 $sql .= " AND i_n.n_givn LIKE CONCAT('%', ?, '%')";
                                 $bind[] = $value;
                             }
                             break;
                         case 'SDX':
                             // SDX uses DM by default.
                         // SDX uses DM by default.
                         case 'SDX_DM':
                             $sdx = WT_Soundex::soundex_dm($value);
                             if ($sdx) {
                                 $sdx = explode(':', $sdx);
                                 foreach ($sdx as $k => $v) {
                                     $sdx[$k] = "i_n.n_soundex_givn_dm LIKE CONCAT('%', ?, '%')";
                                     $bind[] = $v;
                                 }
                                 $sql .= ' AND (' . implode(' OR ', $sdx) . ')';
                             } else {
                                 // No phonetic content?  Use a substring match
                                 $sql .= " AND i_n.n_givn LIKE CONCAT('%', ?, '%')";
                                 $bind[] = $value;
                             }
                             break;
                     }
                     break;
                 case 'SURN':
                     switch ($parts[2]) {
                         case 'EXACT':
                             $sql .= " AND i_n.n_surname=?";
                             $bind[] = $value;
                             break;
                         case 'BEGINS':
                             $sql .= " AND i_n.n_surname LIKE CONCAT(?, '%')";
                             $bind[] = $value;
                             break;
                         case 'CONTAINS':
                             $sql .= " AND i_n.n_surname LIKE CONCAT('%', ?, '%')";
                             $bind[] = $value;
                             break;
                         case 'SDX_STD':
                             $sdx = WT_Soundex::soundex_std($value);
                             if ($sdx) {
                                 $sdx = explode(':', $sdx);
                                 foreach ($sdx as $k => $v) {
                                     $sdx[$k] = "i_n.n_soundex_surn_std LIKE CONCAT('%', ?, '%')";
                                     $bind[] = $v;
                                 }
                                 $sql .= " AND (" . implode(' OR ', $sdx) . ")";
                             } else {
                                 // No phonetic content?  Use a substring match
                                 $sql .= " AND i_n.n_surn LIKE CONCAT('%', ?, '%')";
                                 $bind[] = $value;
                             }
                             break;
                         case 'SDX':
                             // SDX uses DM by default.
                         // SDX uses DM by default.
                         case 'SDX_DM':
                             $sdx = WT_Soundex::soundex_dm($value);
                             if ($sdx) {
                                 $sdx = explode(':', $sdx);
                                 foreach ($sdx as $k => $v) {
                                     $sdx[$k] = "i_n.n_soundex_surn_dm LIKE CONCAT('%', ?, '%')";
                                     $bind[] = $v;
                                 }
                                 $sql .= " AND (" . implode(' OR ', $sdx) . ")";
                                 break;
                             } else {
                                 // No phonetic content?  Use a substring match
                                 $sql .= " AND i_n.n_surn LIKE CONCAT('%', ?, '%')";
                                 $bind[] = $value;
                             }
                     }
                     break;
                 case 'NICK':
                 case '_MARNM':
                 case '_HEB':
                 case '_AKA':
                     $sql .= " AND i_n.n_type=? AND i_n.n_full LIKE CONCAT('%', ?, '%')";
                     $bind[] = $parts[1];
                     $bind[] = $value;
                     break;
             }
         } elseif ($parts[1] == 'DATE') {
             // *:DATE
             $date = new WT_Date($value);
             if ($date->isOK()) {
                 $jd1 = $date->date1->minJD;
                 if ($date->date2) {
                     $jd2 = $date->date2->maxJD;
                 } else {
                     $jd2 = $date->date1->maxJD;
                 }
                 if (!empty($this->plusminus[$i])) {
                     $adjd = $this->plusminus[$i] * 365;
                     //echo $jd1.":".$jd2.":".$adjd;
                     $jd1 = $jd1 - $adjd;
                     $jd2 = $jd2 + $adjd;
                 }
                 $sql .= " AND i_d.d_fact=? AND i_d.d_julianday1>=? AND i_d.d_julianday2<=?";
                 $bind[] = $parts[0];
                 $bind[] = $jd1;
                 $bind[] = $jd2;
             }
         } elseif ($parts[0] == 'FAMS' && $parts[2] == 'DATE') {
             // FAMS:*:DATE
             $date = new WT_Date($value);
             if ($date->isOK()) {
                 $jd1 = $date->date1->minJD;
                 if ($date->date2) {
                     $jd2 = $date->date2->maxJD;
                 } else {
                     $jd2 = $date->date1->maxJD;
                 }
                 if (!empty($this->plusminus[$i])) {
                     $adjd = $this->plusminus[$i] * 365;
                     //echo $jd1.":".$jd2.":".$adjd;
                     $jd1 = $jd1 - $adjd;
                     $jd2 = $jd2 + $adjd;
                 }
                 $sql .= " AND f_d.d_fact=? AND f_d.d_julianday1>=? AND f_d.d_julianday2<=?";
                 $bind[] = $parts[1];
                 $bind[] = $jd1;
                 $bind[] = $jd2;
             }
         } elseif ($parts[1] == 'PLAC') {
             // *:PLAC
             // SQL can only link a place to a person/family, not to an event.
             $sql .= " AND i_p.place LIKE CONCAT('%', ?, '%')";
             //$sql.=" AND i_p.p_place=?";
             $bind[] = $value;
         } elseif ($parts[0] == 'FAMS' && $parts[2] == 'PLAC') {
             // FAMS:*:PLAC
             // SQL can only link a place to a person/family, not to an event.
             $sql .= " AND f_p.place LIKE CONCAT('%', ?, '%')";
             $bind[] = $value;
         } elseif ($parts[0] == 'FAMC' && $parts[2] == 'NAME') {
             $table = $parts[1] == 'HUSB' ? 'f_n' : 'm_n';
             // NAME:*
             switch ($parts[3]) {
                 case 'GIVN':
                     switch ($parts[4]) {
                         case 'EXACT':
                             $sql .= " AND {$table}.n_givn=?";
                             $bind[] = $value;
                             break;
                         case 'BEGINS':
                             $sql .= " AND {$table}.n_givn LIKE CONCAT(?, '%')";
                             $bind[] = $value;
                             break;
                         case 'CONTAINS':
                             $sql .= " AND {$table}.n_givn LIKE CONCAT('%', ?, '%')";
                             $bind[] = $value;
                             break;
                         case 'SDX_STD':
                             $sdx = WT_Soundex::soundex_std($value);
                             if ($sdx) {
                                 $sdx = explode(':', $sdx);
                                 foreach ($sdx as $k => $v) {
                                     $sdx[$k] = "{$table}.n_soundex_givn_std LIKE CONCAT('%', ?, '%')";
                                     $bind[] = $v;
                                 }
                                 $sql .= ' AND (' . implode(' OR ', $sdx) . ')';
                             } else {
                                 // No phonetic content?  Use a substring match
                                 $sql .= " AND {$table}.n_givn = LIKE CONCAT('%', ?, '%')";
                                 $bind[] = $value;
                             }
                             break;
                         case 'SDX':
                             // SDX uses DM by default.
                         // SDX uses DM by default.
                         case 'SDX_DM':
                             $sdx = WT_Soundex::soundex_dm($value);
                             if ($sdx) {
                                 $sdx = explode(':', $sdx);
                                 foreach ($sdx as $k => $v) {
                                     $sdx[$k] = "{$table}.n_soundex_givn_dm LIKE CONCAT('%', ?, '%')";
                                     $bind[] = $v;
                                 }
                                 $sql .= ' AND (' . implode(' OR ', $sdx) . ')';
                                 break;
                             } else {
                                 // No phonetic content?  Use a substring match
                                 $sql .= " AND {$table}.n_givn = LIKE CONCAT('%', ?, '%')";
                                 $bind[] = $value;
                             }
                     }
                     break;
                 case 'SURN':
                     switch ($parts[4]) {
                         case 'EXACT':
                             $sql .= " AND {$table}.n_surname=?";
                             $bind[] = $value;
                             break;
                         case 'BEGINS':
                             $sql .= " AND {$table}.n_surname LIKE CONCAT(?, '%')";
                             $bind[] = $value;
                             break;
                         case 'CONTAINS':
                             $sql .= " AND {$table}.n_surname LIKE CONCAT('%', ?, '%')";
                             $bind[] = $value;
                             break;
                         case 'SDX_STD':
                             $sdx = WT_Soundex::soundex_std($value);
                             if ($sdx) {
                                 $sdx = explode(':', $sdx);
                                 foreach ($sdx as $k => $v) {
                                     $sdx[$k] = "{$table}.n_soundex_surn_std LIKE CONCAT('%', ?, '%')";
                                     $bind[] = $v;
                                 }
                                 $sql .= ' AND (' . implode(' OR ', $sdx) . ')';
                             } else {
                                 // No phonetic content?  Use a substring match
                                 $sql .= " AND {$table}.n_surn = LIKE CONCAT('%', ?, '%')";
                                 $bind[] = $value;
                             }
                             break;
                         case 'SDX':
                             // SDX uses DM by default.
                         // SDX uses DM by default.
                         case 'SDX_DM':
                             $sdx = WT_Soundex::soundex_dm($value);
                             if ($sdx) {
                                 $sdx = explode(':', $sdx);
                                 foreach ($sdx as $k => $v) {
                                     $sdx[$k] = "{$table}.n_soundex_surn_dm LIKE CONCAT('%', ?, '%')";
                                     $bind[] = $v;
                                 }
                                 $sql .= ' AND (' . implode(' OR ', $sdx) . ')';
                             } else {
                                 // No phonetic content?  Use a substring match
                                 $sql .= " AND {$table}.n_surn = LIKE CONCAT('%', ?, '%')";
                                 $bind[] = $value;
                             }
                             break;
                     }
                     break;
             }
         } elseif ($parts[0] == 'FAMS') {
             $sql .= " AND fam.f_gedcom LIKE CONCAT('%', ?, '%')";
             $bind[] = $value;
         } else {
             $sql .= " AND ind.i_gedcom LIKE CONCAT('%', ?, '%')";
             $bind[] = $value;
         }
     }
     $rows = WT_DB::prepare($sql)->execute($bind)->fetchAll();
     foreach ($rows as $row) {
         $person = WT_Individual::getInstance($row->xref, $row->gedcom_id, $row->gedcom);
         // Check for XXXX:PLAC fields, which were only partially matched by SQL
         foreach ($this->fields as $n => $field) {
             if ($this->values[$n] && preg_match('/^(' . WT_REGEX_TAG . '):PLAC$/', $field, $match)) {
                 if (!preg_match('/\\n1 ' . $match[1] . '(\\n[2-9].*)*\\n2 PLAC .*' . preg_quote($this->values[$n], '/') . '/i', $person->getGedcom())) {
                     continue 2;
                 }
             }
         }
         $this->myindilist[] = $person;
     }
 }
Exemple #20
0
 public function getBlock($block_id, $template = true, $cfg = null)
 {
     global $ctype, $WEBTREES_EMAIL;
     $changes = WT_DB::prepare("SELECT 1" . " FROM `##change`" . " WHERE status='pending'" . " LIMIT 1")->fetchOne();
     $days = get_block_setting($block_id, 'days', 1);
     $sendmail = get_block_setting($block_id, 'sendmail', true);
     $block = get_block_setting($block_id, 'block', true);
     if ($cfg) {
         foreach (array('days', 'sendmail', 'block') as $name) {
             if (array_key_exists($name, $cfg)) {
                 ${$name} = $cfg[$name];
             }
         }
     }
     if ($changes && $sendmail == 'yes') {
         // There are pending changes - tell moderators/managers/administrators about them.
         if (WT_TIMESTAMP - WT_Site::getPreference('LAST_CHANGE_EMAIL') > 60 * 60 * 24 * $days) {
             // Which users have pending changes?
             foreach (User::all() as $user) {
                 if ($user->getSetting('contactmethod') !== 'none') {
                     foreach (WT_Tree::getAll() as $tree) {
                         if (exists_pending_change($user, $tree)) {
                             WT_I18N::init($user->getSetting('language'));
                             WT_Mail::systemMessage($tree, $user, WT_I18N::translate('Pending changes'), WT_I18N::translate('There are pending changes for you to moderate.') . WT_Mail::EOL . WT_MAIL::EOL . '<a href="' . WT_SERVER_NAME . WT_SCRIPT_PATH . 'index.php?ged=' . WT_GEDURL . '">' . WT_SERVER_NAME . WT_SCRIPT_PATH . 'index.php?ged=' . WT_GEDURL . '</a>');
                             WT_I18N::init(WT_LOCALE);
                         }
                     }
                 }
             }
             WT_Site::setPreference('LAST_CHANGE_EMAIL', WT_TIMESTAMP);
         }
         if (WT_USER_CAN_EDIT) {
             $id = $this->getName() . $block_id;
             $class = $this->getName() . '_block';
             if ($ctype == 'gedcom' && WT_USER_GEDCOM_ADMIN || $ctype == 'user' && WT_USER_ID) {
                 $title = '<i class="icon-admin" title="' . WT_I18N::translate('Configure') . '" onclick="modalDialog(\'block_edit.php?block_id=' . $block_id . '\', \'' . $this->getTitle() . '\');"></i>';
             } else {
                 $title = '';
             }
             $title .= $this->getTitle() . help_link('review_changes', $this->getName());
             $content = '';
             if (WT_USER_CAN_ACCEPT) {
                 $content .= "<a href=\"#\" onclick=\"window.open('edit_changes.php','_blank', chan_window_specs); return false;\">" . WT_I18N::translate('There are pending changes for you to moderate.') . "</a><br>";
             }
             if ($sendmail == "yes") {
                 $content .= WT_I18N::translate('Last email reminder was sent ') . format_timestamp(WT_Site::getPreference('LAST_CHANGE_EMAIL')) . "<br>";
                 $content .= WT_I18N::translate('Next email reminder will be sent after ') . format_timestamp(WT_Site::getPreference('LAST_CHANGE_EMAIL') + 60 * 60 * 24 * $days) . "<br><br>";
             }
             $changes = WT_DB::prepare("SELECT xref" . " FROM  `##change`" . " WHERE status='pending'" . " AND   gedcom_id=?" . " GROUP BY xref")->execute(array(WT_GED_ID))->fetchAll();
             foreach ($changes as $change) {
                 $record = WT_GedcomRecord::getInstance($change->xref);
                 if ($record->canShow()) {
                     $content .= '<b>' . $record->getFullName() . '</b>';
                     $content .= $block ? '<br>' : ' ';
                     $content .= '<a href="' . $record->getHtmlUrl() . '">' . WT_I18N::translate('View the changes') . '</a>';
                     $content .= '<br>';
                 }
             }
             if ($template) {
                 if ($block) {
                     require WT_THEME_DIR . 'templates/block_small_temp.php';
                 } else {
                     require WT_THEME_DIR . 'templates/block_main_temp.php';
                 }
             } else {
                 return $content;
             }
         }
     }
 }
Exemple #21
0
    public function getBlock($block_id, $template = true, $cfg = null)
    {
        global $ctype, $foundlist;
        $filter = get_block_setting($block_id, 'filter', 'all');
        $controls = get_block_setting($block_id, 'controls', true);
        $start = get_block_setting($block_id, 'start', false) || WT_Filter::getBool('start');
        $block = get_block_setting($block_id, 'block', true);
        // We can apply the filters using SQL
        // Do not use "ORDER BY RAND()" - it is very slow on large tables.  Use PHP::array_rand() instead.
        $all_media = WT_DB::prepare("SELECT m_id FROM `##media`" . " WHERE m_file = ?" . " AND m_ext  IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, '')" . " AND m_type IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, '')")->execute(array(WT_GED_ID, get_block_setting($block_id, 'filter_avi', false) ? 'avi' : NULL, get_block_setting($block_id, 'filter_bmp', true) ? 'bmp' : NULL, get_block_setting($block_id, 'filter_gif', true) ? 'gif' : NULL, get_block_setting($block_id, 'filter_jpeg', true) ? 'jpg' : NULL, get_block_setting($block_id, 'filter_jpeg', true) ? 'jpeg' : NULL, get_block_setting($block_id, 'filter_mp3', false) ? 'mp3' : NULL, get_block_setting($block_id, 'filter_ole', true) ? 'ole' : NULL, get_block_setting($block_id, 'filter_pcx', true) ? 'pcx' : NULL, get_block_setting($block_id, 'filter_pdf', false) ? 'pdf' : NULL, get_block_setting($block_id, 'filter_png', true) ? 'png' : NULL, get_block_setting($block_id, 'filter_tiff', true) ? 'tiff' : NULL, get_block_setting($block_id, 'filter_wav', false) ? 'wav' : NULL, get_block_setting($block_id, 'filter_audio', false) ? 'audio' : NULL, get_block_setting($block_id, 'filter_book', true) ? 'book' : NULL, get_block_setting($block_id, 'filter_card', true) ? 'card' : NULL, get_block_setting($block_id, 'filter_certificate', true) ? 'certificate' : NULL, get_block_setting($block_id, 'filter_coat', true) ? 'coat' : NULL, get_block_setting($block_id, 'filter_document', true) ? 'document' : NULL, get_block_setting($block_id, 'filter_electronic', true) ? 'electronic' : NULL, get_block_setting($block_id, 'filter_fiche', true) ? 'fiche' : NULL, get_block_setting($block_id, 'filter_film', true) ? 'film' : NULL, get_block_setting($block_id, 'filter_magazine', true) ? 'magazine' : NULL, get_block_setting($block_id, 'filter_manuscript', true) ? 'manuscript' : NULL, get_block_setting($block_id, 'filter_map', true) ? 'map' : NULL, get_block_setting($block_id, 'filter_newspaper', true) ? 'newspaper' : NULL, get_block_setting($block_id, 'filter_other', true) ? 'other' : NULL, get_block_setting($block_id, 'filter_painting', true) ? 'painting' : NULL, get_block_setting($block_id, 'filter_photo', true) ? 'photo' : NULL, get_block_setting($block_id, 'filter_tombstone', true) ? 'tombstone' : NULL, get_block_setting($block_id, 'filter_video', false) ? 'video' : NULL))->fetchOneColumn();
        // Keep looking through the media until a suitable one is found.
        $random_media = null;
        while ($all_media) {
            $n = array_rand($all_media);
            $media = WT_Media::getInstance($all_media[$n]);
            if ($media->canShow() && !$media->isExternal()) {
                // Check if it is linked to a suitable individual
                foreach ($media->linkedIndividuals('OBJE') as $indi) {
                    if ($filter == 'all' || $filter == 'indi' && strpos($indi->getGedcom(), "\n1 OBJE @" . $media->getXref() . '@') !== false || $filter == 'event' && strpos($indi->getGedcom(), "\n2 OBJE @" . $media->getXref() . '@') !== false) {
                        // Found one :-)
                        $random_media = $media;
                        break 2;
                    }
                }
            }
            unset($all_media[$n]);
        }
        $id = $this->getName() . $block_id;
        $class = $this->getName() . '_block';
        if ($ctype == 'gedcom' && WT_USER_GEDCOM_ADMIN || $ctype == 'user' && WT_USER_ID) {
            $title = '<i class="icon-admin" title="' . WT_I18N::translate('Configure') . '" onclick="modalDialog(\'block_edit.php?block_id=' . $block_id . '\', \'' . $this->getTitle() . '\');"></i>';
        } else {
            $title = '';
        }
        $title .= $this->getTitle();
        if ($random_media) {
            $content = "<div id=\"random_picture_container{$block_id}\">";
            if ($controls) {
                if ($start) {
                    $icon_class = 'icon-media-stop';
                } else {
                    $icon_class = 'icon-media-play';
                }
                $content .= '<div dir="ltr" class="center" id="random_picture_controls' . $block_id . '"><br>';
                $content .= "<a href=\"#\" onclick=\"togglePlay(); return false;\" id=\"play_stop\" class=\"" . $icon_class . "\" title=\"" . WT_I18N::translate('Play') . "/" . WT_I18N::translate('Stop') . '"></a>';
                $content .= '<a href="#" onclick="jQuery(\'#block_' . $block_id . '\').load(\'index.php?ctype=' . $ctype . '&amp;action=ajax&amp;block_id=' . $block_id . '\');return false;" title="' . WT_I18N::translate('Next image') . '" class="icon-media-next"></a>';
                $content .= '</div><script>
					var play = false;
						function togglePlay() {
							if (play) {
								play = false;
								jQuery("#play_stop").removeClass("icon-media-stop").addClass("icon-media-play");
							}
							else {
								play = true;
								playSlideShow();
								jQuery("#play_stop").removeClass("icon-media-play").addClass("icon-media-stop");
							}
						}

						function playSlideShow() {
							if (play) {
								window.setTimeout("reload_image()", 6000);
							}
						}
						function reload_image() {
							if (play) {
								jQuery("#block_' . $block_id . '").load("index.php?ctype=' . $ctype . '&action=ajax&block_id=' . $block_id . '&start=1");
							}
						}
					</script>';
            }
            if ($start) {
                $content .= '<script>togglePlay();</script>';
            }
            $content .= '<div class="center" id="random_picture_content' . $block_id . '">';
            $content .= '<table id="random_picture_box"><tr><td';
            if ($block) {
                $content .= ' class="details1"';
            } else {
                $content .= ' class="details2"';
            }
            $content .= ' >';
            $content .= $random_media->displayImage();
            if ($block) {
                $content .= '<br>';
            } else {
                $content .= '</td><td class="details2">';
            }
            $content .= '<a href="' . $random_media->getHtmlUrl() . '"><b>' . $random_media->getFullName() . '</b></a><br>';
            foreach ($random_media->linkedIndividuals('OBJE') as $individual) {
                $content .= '<a href="' . $individual->getHtmlUrl() . '">' . WT_I18N::translate('View person') . ' — ' . $individual->getFullname() . '</a><br>';
            }
            foreach ($random_media->linkedFamilies('OBJE') as $family) {
                $content .= '<a href="' . $family->getHtmlUrl() . '">' . WT_I18N::translate('View family') . ' — ' . $family->getFullname() . '</a><br>';
            }
            foreach ($random_media->linkedSources('OBJE') as $source) {
                $content .= '<a href="' . $source->getHtmlUrl() . '">' . WT_I18N::translate('View source') . ' — ' . $source->getFullname() . '</a><br>';
            }
            $content .= '<br><div class="indent">';
            $content .= print_fact_notes($random_media->getGedcom(), "1", false, true);
            $content .= '</div>';
            $content .= '</td></tr></table>';
            $content .= '</div>';
            // random_picture_content
            $content .= '</div>';
            // random_picture_container
        } else {
            $content = WT_I18N::translate('This family tree has no images to display.');
        }
        if ($template) {
            require WT_THEME_DIR . 'templates/block_main_temp.php';
        } else {
            return $content;
        }
    }
Exemple #22
0
/**
 * Gets the news item for the given news id
 *
 * @param int $news_id the id of the news entry to get
 *
 * @return array|null
 */
function getNewsItem($news_id)
{
    $row = WT_DB::prepare("SELECT SQL_CACHE news_id, user_id, gedcom_id, UNIX_TIMESTAMP(updated) AS updated, subject, body FROM `##news` WHERE news_id=?")->execute(array($news_id))->fetchOneRow();
    if ($row) {
        return array('id' => $row->news_id, 'user_id' => $row->user_id, 'gedcom_id' => $row->gedcom_id, 'date' => $row->updated, 'title' => $row->subject, 'text' => $row->body);
    } else {
        return null;
    }
}
Exemple #23
0
                // existing block moved location
                WT_DB::prepare("UPDATE `##block` SET location=? WHERE block_id=?")->execute(array($location, $block_name));
            } else {
                // new block
                if ($user_id) {
                    WT_DB::prepare("INSERT INTO `##block` (user_id, location, block_order, module_name) VALUES (?, ?, ?, ?)")->execute(array($user_id, $location, $order, $block_name));
                } else {
                    WT_DB::prepare("INSERT INTO `##block` (gedcom_id, location, block_order, module_name) VALUES (?, ?, ?, ?)")->execute(array($gedcom_id, $location, $order, $block_name));
                }
            }
        }
        // deleted blocks
        foreach ($blocks[$location] as $block_id => $block_name) {
            if (!in_array($block_id, $main) && !in_array($block_id, $right)) {
                WT_DB::prepare("DELETE FROM `##block_setting` WHERE block_id=?")->execute(array($block_id));
                WT_DB::prepare("DELETE FROM `##block`         WHERE block_id=?")->execute(array($block_id));
            }
        }
    }
    exit;
}
$controller->pageHeader()->addInlineJavascript('
	/**
	 * Move Up Block Javascript function
	 *
	 * This function moves the selected option up in the given select list
	 *
	 * @param String section_name the name of the select to move the options
	 */
	function move_up_block(section_name) {
		section_select = document.getElementById(section_name);
Exemple #24
0
 protected static function updateSchema()
 {
     // Create tables, if not already present
     try {
         WT_DB::updateSchema(WT_ROOT . WT_MODULES_DIR . 'gedcom_favorites/db_schema/', 'FV_SCHEMA_VERSION', 4);
     } catch (PDOException $ex) {
         // The schema update scripts should never fail.  If they do, there is no clean recovery.
         die($ex);
     }
 }
Exemple #25
0
 public function __call($function, $params)
 {
     switch ($function) {
         case 'closeCursor':
             $this->executed = false;
             // no break;
         // no break;
         case 'bindColumn':
         case 'bindParam':
         case 'bindValue':
             // TODO: bind variables need to be stored in $this->bind_variables so we can log them
         // TODO: bind variables need to be stored in $this->bind_variables so we can log them
         case 'setAttribute':
         case 'setFetchMode':
             // Functions that return no values become fluent
             call_user_func_array(array($this->pdostatement, $function), $params);
             return $this;
         case 'execute':
             if ($this->executed) {
                 trigger_error('WT_DBStatement::execute() called twice.', E_USER_ERROR);
             } else {
                 if ($params) {
                     $this->bind_variables = $params[0];
                     foreach ($params[0] as &$param) {
                         if ($param === false) {
                             // For consistency, otherwise true=>'1' and false=>''
                             $param = 0;
                         }
                     }
                 }
                 $start = microtime(true);
                 call_user_func_array(array($this->pdostatement, $function), $params);
                 $end = microtime(true);
                 $this->executed = !preg_match('/^(insert|delete|update|create|alter) /i', $this->pdostatement->queryString);
                 WT_DB::logQuery($this->pdostatement->queryString, $this->pdostatement->rowCount(), $end - $start, $this->bind_variables);
                 return $this;
             }
         case 'fetch':
         case 'fetchColumn':
         case 'fetchObject':
         case 'fetchAll':
             // Automatically execute the query
             if (!$this->executed) {
                 $this->execute();
                 $this->executed = true;
             }
             // no break;
         // no break;
         default:
             return call_user_func_array(array($this->pdostatement, $function), $params);
     }
 }
Exemple #26
0
function all_media_files($media_folder, $media_path, $subfolders, $filter)
{
    return WT_DB::prepare("SELECT SQL_CACHE SQL_CALC_FOUND_ROWS TRIM(LEADING ? FROM m_filename) AS media_path, 'OBJE' AS type, m_titl, m_id AS xref, m_file AS ged_id, m_gedcom AS gedrec, m_filename" . " FROM  `##media`" . " JOIN  `##gedcom_setting` ON (m_file = gedcom_id AND setting_name = 'MEDIA_DIRECTORY')" . " JOIN  `##gedcom`         USING (gedcom_id)" . " WHERE setting_value=?" . " AND   m_filename LIKE CONCAT(?, '%')" . " AND   (SUBSTRING_INDEX(m_filename, '/', -1) LIKE CONCAT('%', ?, '%')" . "  OR   m_titl LIKE CONCAT('%', ?, '%'))" . "\tAND   m_filename NOT LIKE 'http://%'" . " AND   m_filename NOT LIKE 'https://%'")->execute(array($media_path, $media_folder, WT_Filter::escapeLike($media_path), WT_Filter::escapeLike($filter), WT_Filter::escapeLike($filter)))->fetchOneColumn();
}
Exemple #27
0
//
// The script should assume that it can be interrupted at
// any point, and be able to continue by re-running the script.
// Fatal errors, however, should be allowed to throw exceptions,
// which will be caught by the framework.
// It shouldn't do anything that might take more than a few
// seconds, for systems with low timeout values.
//
// webtrees: Web based Family History software
// Copyright (C) 2014 webtrees development team.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
if (!defined('WT_WEBTREES')) {
    header('HTTP/1.0 403 Forbidden');
    exit;
}
WT_DB::exec("CREATE TABLE IF NOT EXISTS `##news` (" . " n_id       INTEGER AUTO_INCREMENT NOT NULL," . " n_username VARCHAR(100)           NOT NULL," . " n_date     INTEGER                NOT NULL," . " n_title    VARCHAR(255)           NOT NULL," . " n_text     TEXT                   NOT NULL," . " PRIMARY KEY     (n_id)," . "         KEY ix1 (n_username)" . ") COLLATE utf8_unicode_ci ENGINE=InnoDB");
// Update the version to indicate success
WT_Site::setPreference($schema_name, $next_version);
Exemple #28
0
    define('WT_USER_GEDCOM_ID', '');
    define('WT_USER_ROOT_ID', '');
    define('WT_USER_PATH_LENGTH', 0);
    define('WT_USER_ACCESS_LEVEL', WT_PRIV_PUBLIC);
}
$GEDCOM = WT_GEDCOM;
// With no parameters, init() looks to the environment to choose a language
define('WT_LOCALE', WT_I18N::init());
$WT_SESSION->locale = WT_I18N::$locale;
// Set our gedcom selection as a default for the next page
$WT_SESSION->GEDCOM = WT_GEDCOM;
if (empty($WEBTREES_EMAIL)) {
    $WEBTREES_EMAIL = 'webtrees-noreply@' . preg_replace('/^www\\./i', '', $_SERVER['SERVER_NAME']);
}
// Note that the database/webservers may not be synchronised, so use DB time throughout.
define('WT_TIMESTAMP', (int) WT_DB::prepare("SELECT UNIX_TIMESTAMP()")->fetchOne());
// Server timezone is defined in php.ini
define('WT_SERVER_TIMESTAMP', WT_TIMESTAMP + (int) date('Z'));
if (WT_USER_ID) {
    define('WT_CLIENT_TIMESTAMP', WT_TIMESTAMP - $WT_SESSION->timediff);
} else {
    define('WT_CLIENT_TIMESTAMP', WT_SERVER_TIMESTAMP);
}
define('WT_CLIENT_JD', 2440588 + (int) (WT_CLIENT_TIMESTAMP / 86400));
// Application configuration data - things that aren’t (yet?) user-editable
require WT_ROOT . 'includes/config_data.php';
// The login URL must be an absolute URL, and can be user-defined
if (WT_Site::preference('LOGIN_URL')) {
    define('WT_LOGIN_URL', WT_Site::preference('LOGIN_URL'));
} else {
    define('WT_LOGIN_URL', WT_SERVER_NAME . WT_SCRIPT_PATH . 'login.php');
Exemple #29
0
             $datum[10] = format_timestamp($datum[9]) . '<br>' . WT_I18N::time_ago(WT_TIMESTAMP - $datum[9]);
         } else {
             $datum[10] = WT_I18N::translate('Never');
         }
         $datum[11] = edit_field_yes_no_inline('user_setting-' . $user_id . '-verified-', $datum[11]);
         $datum[12] = edit_field_yes_no_inline('user_setting-' . $user_id . '-verified_by_admin-', $datum[12]);
         // Add extra column for "delete" action
         if ($user_id != WT_USER_ID) {
             $datum[13] = '<div class="icon-delete" onclick="delete_user(\'' . WT_I18N::translate('Are you sure you want to delete “%s”?', WT_Filter::escapeJs($user_name)) . '\', \'' . WT_Filter::escapeJs($user_id) . '\');"></div>';
         } else {
             // Do not delete ourself!
             $datum[13] = '';
         }
     }
     // Total filtered/unfiltered rows
     $recordsFiltered = WT_DB::prepare("SELECT FOUND_ROWS()")->fetchOne();
     $recordsTotal = User::count();
     Zend_Session::writeClose();
     header('Content-type: application/json');
     echo json_encode(array('draw' => WT_Filter::getInteger('draw'), 'recordsTotal' => $recordsTotal, 'recordsFiltered' => $recordsFiltered, 'data' => $data));
     exit;
 case 'load1row':
     // Generate an AJAX response for datatables to load expanded row
     $user_id = WT_Filter::getInteger('user_id');
     $user = User::find($user_id);
     Zend_Session::writeClose();
     header('Content-type: text/html; charset=UTF-8');
     echo '<h2>', WT_I18N::translate('Details'), '</h2>';
     echo '<dl>';
     echo '<dt>', WT_I18N::translate('Administrator'), '</dt>';
     echo '<dd>', edit_field_yes_no_inline('user_setting-' . $user_id . '-canadmin', $user->getSetting('canadmin')), '</dd>';
Exemple #30
0
//
// webtrees: Web based Family History software
// Copyright (C) 2014 webtrees development team.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
if (!defined('WT_WEBTREES')) {
    header('HTTP/1.0 403 Forbidden');
    exit;
}
// Delete any data that might violate the new constraints
WT_DB::exec("DELETE FROM `##news`" . " WHERE user_id   NOT IN (SELECT user_id   FROM `##user`  )" . " OR    gedcom_id NOT IN (SELECT gedcom_id FROM `##gedcom`)");
// Add the new constraints
try {
    WT_DB::exec("ALTER TABLE `##news`" . " ADD FOREIGN KEY news_fk1 (user_id  ) REFERENCES `##user`   (user_id)   ON DELETE CASCADE," . " ADD FOREIGN KEY news_fk2 (gedcom_id) REFERENCES `##gedcom` (gedcom_id) ON DELETE CASCADE");
} catch (PDOException $ex) {
    // Already updated?
}
// Update the version to indicate success
WT_Site::setPreference($schema_name, $next_version);