Ejemplo n.º 1
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'));
 }
Ejemplo n.º 2
0
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);
}
Ejemplo n.º 3
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();
 }
Ejemplo n.º 4
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();
 }
Ejemplo n.º 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 . '"');
     }
 }
Ejemplo n.º 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;
     }
 }
Ejemplo n.º 7
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;
     }
 }
Ejemplo n.º 8
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();
}
Ejemplo n.º 9
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');
Ejemplo n.º 10
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();
}
Ejemplo n.º 11
0
 public static function getFavorites($gedcom_id)
 {
     self::updateSchema();
     // make sure the favorites table has been created
     return WT_DB::prepare("SELECT SQL_CACHE favorite_id AS id, user_id, gedcom_id, xref AS gid, favorite_type AS type, title, note, url" . " FROM `##favorite` WHERE gedcom_id=? AND user_id IS NULL")->execute(array($gedcom_id))->fetchAll(PDO::FETCH_ASSOC);
 }
Ejemplo n.º 12
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;
 }
Ejemplo n.º 13
0
    private function show_list()
    {
        global $controller;
        $controller = new WT_Controller_Page();
        $controller->setPageTitle($this->getTitle())->pageHeader()->addExternalJavascript(WT_JQUERY_DATATABLES_URL)->addInlineJavascript('
				jQuery("#story_table").dataTable({
					dom: \'<"H"pf<"dt-clear">irl>t<"F"pl>\',
					' . WT_I18N::datatablesI18N() . ',
					autoWidth: false,
					paging: true,
					pagingType: "full_numbers",
					lengthChange: true,
					filter: true,
					info: true,
					jQueryUI: true,
					sorting: [[0,"asc"]],
					columns: [
						/* 0-name */ null,
						/* 1-NAME */ null
					]
				});
			');
        $stories = WT_DB::prepare("SELECT block_id, xref" . " FROM `##block` b" . " WHERE module_name=?" . " AND gedcom_id=?" . " ORDER BY xref")->execute(array($this->getName(), WT_GED_ID))->fetchAll();
        echo '<h2 class="center">', WT_I18N::translate('Stories'), '</h2>';
        if (count($stories) > 0) {
            echo '<table id="story_table" class="width100">';
            echo '<thead><tr>
				<th>', WT_I18N::translate('Story title'), '</th>
				<th>', WT_I18N::translate('Individual'), '</th>
				</tr></thead>
				<tbody>';
            foreach ($stories as $story) {
                $indi = WT_Individual::getInstance($story->xref);
                $story_title = get_block_setting($story->block_id, 'title');
                $languages = get_block_setting($story->block_id, 'languages');
                if (!$languages || in_array(WT_LOCALE, explode(',', $languages))) {
                    if ($indi) {
                        if ($indi->canShow()) {
                            echo '<tr><td><a href="' . $indi->getHtmlUrl() . '#stories">' . $story_title . '</a></td><td><a href="' . $indi->getHtmlUrl() . '#stories">' . $indi->getFullName() . '</a></td></tr>';
                        }
                    } else {
                        echo '<tr><td>', $story_title, '</td><td class="error">', $story->xref, '</td></tr>';
                    }
                }
            }
            echo '</tbody></table>';
        }
    }
Ejemplo n.º 14
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);
Ejemplo n.º 15
0
                    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) . ',
Ejemplo n.º 16
0
 public static function setDefaultAccess($ged_id)
 {
     foreach (self::getInstalledModules('disabled') as $module) {
         if ($module instanceof WT_Module_Menu) {
             WT_DB::prepare("INSERT IGNORE `##module_privacy` (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'menu', ?)")->execute(array($module->getName(), $ged_id, $module->defaultAccessLevel()));
         }
         if ($module instanceof WT_Module_Sidebar) {
             WT_DB::prepare("INSERT IGNORE `##module_privacy` (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'sidebar', ?)")->execute(array($module->getName(), $ged_id, $module->defaultAccessLevel()));
         }
         if ($module instanceof WT_Module_Tab) {
             WT_DB::prepare("INSERT IGNORE `##module_privacy` (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'tab', ?)")->execute(array($module->getName(), $ged_id, $module->defaultAccessLevel()));
         }
         if ($module instanceof WT_Module_Block) {
             WT_DB::prepare("INSERT IGNORE `##module_privacy` (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'block', ?)")->execute(array($module->getName(), $ged_id, $module->defaultAccessLevel()));
         }
         if ($module instanceof WT_Module_Chart) {
             WT_DB::prepare("INSERT IGNORE `##module_privacy` (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'chart', ?)")->execute(array($module->getName(), $ged_id, $module->defaultAccessLevel()));
         }
         if ($module instanceof WT_Module_Report) {
             WT_DB::prepare("INSERT IGNORE `##module_privacy` (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'report', ?)")->execute(array($module->getName(), $ged_id, $module->defaultAccessLevel()));
         }
         if ($module instanceof WT_Module_Theme) {
             WT_DB::prepare("INSERT IGNORE `##module_privacy` (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'theme', ?)")->execute(array($module->getName(), $ged_id, $module->defaultAccessLevel()));
         }
     }
 }
Ejemplo n.º 17
0
 $mail1_body .= WT_Mail::EOL . '<a href="' . WT_SERVER_NAME . WT_SCRIPT_PATH . "admin_users.php?filter=" . rawurlencode($user->getUserName()) . '">' . WT_SERVER_NAME . WT_SCRIPT_PATH . "admin_users.php?filter=" . rawurlencode($user->getUserName()) . '</a>' . WT_Mail::auditFooter();
 $mail1_subject = WT_I18N::translate('New user at %s', WT_SERVER_NAME . WT_SCRIPT_PATH . ' ' . $WT_TREE->tree_title);
 // Change to the new user’s language
 WT_I18N::init($user->getSetting('language'));
 $controller->setPageTitle(WT_I18N::translate('User verification'));
 $controller->pageHeader();
 echo '<div id="login-register-page">';
 echo '<h2>' . WT_I18N::translate('User verification') . '</h2>';
 echo '<div id="user-verify">';
 echo WT_I18N::translate('The data for the user <b>%s</b> was checked.', $user_name);
 if ($user) {
     if ($user->checkPassword($user_password) && $user->getSetting('reg_hashcode') == $user_hashcode) {
         WT_Mail::send($WT_TREE, $webmaster->getEmail(), $webmaster->getRealName(), $WEBTREES_EMAIL, $WEBTREES_EMAIL, $mail1_subject, $mail1_body);
         $mail1_method = $webmaster->getSetting('CONTACT_METHOD');
         if ($mail1_method != 'messaging3' && $mail1_method != 'mailto' && $mail1_method != 'none') {
             WT_DB::prepare("INSERT INTO `##message` (sender, ip_address, user_id, subject, body) VALUES (? ,? ,? ,? ,?)")->execute(array($user_name, $WT_REQUEST->getClientIp(), $webmaster->getUserId(), $mail1_subject, WT_Filter::unescapeHtml($mail1_body)));
         }
         $user->setSetting('verified', 1)->setSetting('reg_timestamp', date("U"))->setSetting('reg_hashcode', null);
         if (!$REQUIRE_ADMIN_AUTH_REGISTRATION) {
             set_user_setting($user_id, 'verified_by_admin', 1);
         }
         Log::addAuthenticationLog('User ' . $user_name . ' verified their email address');
         echo '<br><br>' . WT_I18N::translate('You have confirmed your request to become a registered user.') . '<br><br>';
         if ($REQUIRE_ADMIN_AUTH_REGISTRATION && !$user->getSetting('verified_by_admin')) {
             echo WT_I18N::translate('The administrator has been informed.  As soon as he gives you permission to login, you can login with your user name and password.');
         } else {
             echo WT_I18N::translate('You can now login with your user name and password.');
         }
         echo '<br><br>';
     } else {
         Log::addAuthenticationLog('User ' . $user_name . ' failed to verify their email address');
Ejemplo n.º 18
0
                exit;
        }
        $first_time = false;
        // Re-fetch the data, now that we have performed character set conversion.
        $data = WT_DB::prepare("SELECT gedcom_chunk_id, REPLACE(chunk_data, '\r', '\n') AS chunk_data" . " FROM `##gedcom_chunk`" . " WHERE gedcom_chunk_id=?")->execute(array($data->gedcom_chunk_id))->fetchOneRow();
    }
    if (!$data) {
        break;
    }
    try {
        // Import all the records in this chunk of data
        foreach (preg_split('/\\n+(?=0)/', $data->chunk_data) as $rec) {
            import_record($rec, $gedcom_id, false);
        }
        // Mark the chunk as imported
        WT_DB::prepare("UPDATE `##gedcom_chunk` SET imported=TRUE WHERE gedcom_chunk_id=?")->execute(array($data->gedcom_chunk_id));
    } catch (PDOException $ex) {
        WT_DB::exec("ROLLBACK");
        if ($ex->getCode() == '40001') {
            // "SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction"
            // The documentation says that if you get this error, wait and try again.....
            sleep(1);
            $controller->addInlineJavascript('jQuery("#import' . $gedcom_id . '").load("import.php?gedcom_id=' . $gedcom_id . '&u=' . uniqid() . '");');
        } else {
            // A fatal error.  Nothing we can do?
            echo '<span class="error">', $ex->getMessage(), '</span>';
            $controller->addInlineJavascript('jQuery("#actions' . $gedcom_id . '").toggle();');
        }
        exit;
    }
}
Ejemplo n.º 19
0
    private function adminPlaces()
    {
        require WT_ROOT . 'includes/functions/functions_edit.php';
        $action = WT_Filter::get('action');
        $parent = WT_Filter::get('parent');
        $inactive = WT_Filter::getBool('inactive');
        $deleteRecord = WT_Filter::get('deleteRecord');
        if (!isset($parent)) {
            $parent = 0;
        }
        $controller = new WT_Controller_Page();
        $controller->restrictAccess(Auth::isAdmin());
        if ($action == 'ExportFile' && Auth::isAdmin()) {
            Zend_Session::writeClose();
            $tmp = $this->placeIdToHierarchy($parent);
            $maxLevel = $this->getHighestLevel();
            if ($maxLevel > 8) {
                $maxLevel = 8;
            }
            $tmp[0] = 'places';
            $outputFileName = preg_replace('/[:;\\/\\\\(\\)\\{\\}\\[\\] $]/', '_', implode('-', $tmp)) . '.csv';
            header('Content-Type: application/octet-stream');
            header('Content-Disposition: attachment; filename="' . $outputFileName . '"');
            echo '"', WT_I18N::translate('Level'), '";"', WT_I18N::translate('Country'), '";';
            if ($maxLevel > 0) {
                echo '"', WT_I18N::translate('State'), '";';
            }
            if ($maxLevel > 1) {
                echo '"', WT_I18N::translate('County'), '";';
            }
            if ($maxLevel > 2) {
                echo '"', WT_I18N::translate('City'), '";';
            }
            if ($maxLevel > 3) {
                echo '"', WT_I18N::translate('Place'), '";';
            }
            if ($maxLevel > 4) {
                echo '"', WT_I18N::translate('Place'), '";';
            }
            if ($maxLevel > 5) {
                echo '"', WT_I18N::translate('Place'), '";';
            }
            if ($maxLevel > 6) {
                echo '"', WT_I18N::translate('Place'), '";';
            }
            if ($maxLevel > 7) {
                echo '"', WT_I18N::translate('Place'), '";';
            }
            echo '"', WT_I18N::translate('Longitude'), '";"', WT_I18N::translate('Latitude'), '";';
            echo '"', WT_I18N::translate('Zoom level'), '";"', WT_I18N::translate('Icon'), '";', WT_EOL;
            $this->outputLevel($parent);
            exit;
        }
        $controller->setPageTitle(WT_I18N::translate('Google Maps™'))->pageHeader();
        ?>
		<table id="gm_config">
			<tr>
				<th>
					<a href="module.php?mod=googlemap&amp;mod_action=admin_config">
						<?php 
        echo WT_I18N::translate('Google Maps™ preferences');
        ?>
					</a>
				</th>
				<th>
					<a class="current" href="module.php?mod=googlemap&amp;mod_action=admin_places">
						<?php 
        echo WT_I18N::translate('Geographic data');
        ?>
					</a>
				</th>
				<th>
					<a href="module.php?mod=googlemap&amp;mod_action=admin_placecheck">
						<?php 
        echo WT_I18N::translate('Place check');
        ?>
					</a>
				</th>
			</tr>
		</table>
		<?php 
        if ($action == 'ImportGedcom') {
            $placelist = array();
            $j = 0;
            $gedcom_records = WT_DB::prepare("SELECT i_gedcom FROM `##individuals` WHERE i_file=? UNION ALL SELECT f_gedcom FROM `##families` WHERE f_file=?")->execute(array(WT_GED_ID, WT_GED_ID))->fetchOneColumn();
            foreach ($gedcom_records as $gedrec) {
                $i = 1;
                $placerec = get_sub_record(2, '2 PLAC', $gedrec, $i);
                while (!empty($placerec)) {
                    if (preg_match("/2 PLAC (.+)/", $placerec, $match)) {
                        $placelist[$j] = array();
                        $placelist[$j]['place'] = trim($match[1]);
                        if (preg_match("/4 LATI (.*)/", $placerec, $match)) {
                            $placelist[$j]['lati'] = trim($match[1]);
                            if ($placelist[$j]['lati'][0] != 'N' && $placelist[$j]['lati'][0] != 'S') {
                                if ($placelist[$j]['lati'] < 0) {
                                    $placelist[$j]['lati'][0] = 'S';
                                } else {
                                    $placelist[$j]['lati'] = 'N' . $placelist[$j]['lati'];
                                }
                            }
                        } else {
                            $placelist[$j]['lati'] = NULL;
                        }
                        if (preg_match("/4 LONG (.*)/", $placerec, $match)) {
                            $placelist[$j]['long'] = trim($match[1]);
                            if ($placelist[$j]['long'][0] != 'E' && $placelist[$j]['long'][0] != 'W') {
                                if ($placelist[$j]['long'] < 0) {
                                    $placelist[$j]['long'][0] = 'W';
                                } else {
                                    $placelist[$j]['long'] = 'E' . $placelist[$j]['long'];
                                }
                            }
                        } else {
                            $placelist[$j]['long'] = NULL;
                        }
                        $j = $j + 1;
                    }
                    $i = $i + 1;
                    $placerec = get_sub_record(2, '2 PLAC', $gedrec, $i);
                }
            }
            asort($placelist);
            $prevPlace = '';
            $prevLati = '';
            $prevLong = '';
            $placelistUniq = array();
            $j = 0;
            foreach ($placelist as $k => $place) {
                if ($place['place'] != $prevPlace) {
                    $placelistUniq[$j] = array();
                    $placelistUniq[$j]['place'] = $place['place'];
                    $placelistUniq[$j]['lati'] = $place['lati'];
                    $placelistUniq[$j]['long'] = $place['long'];
                    $j = $j + 1;
                } elseif ($place['place'] == $prevPlace && ($place['lati'] != $prevLati || $place['long'] != $prevLong)) {
                    if ($placelistUniq[$j - 1]['lati'] == 0 || $placelistUniq[$j - 1]['long'] == 0) {
                        $placelistUniq[$j - 1]['lati'] = $place['lati'];
                        $placelistUniq[$j - 1]['long'] = $place['long'];
                    } elseif ($place['lati'] != '0' || $place['long'] != '0') {
                        echo 'Difference: previous value = ', $prevPlace, ', ', $prevLati, ', ', $prevLong, ' current = ', $place['place'], ', ', $place['lati'], ', ', $place['long'], '<br>';
                    }
                }
                $prevPlace = $place['place'];
                $prevLati = $place['lati'];
                $prevLong = $place['long'];
            }
            $highestIndex = $this->getHighestIndex();
            $default_zoom_level = array(4, 7, 10, 12);
            foreach ($placelistUniq as $k => $place) {
                $parent = preg_split('/ *, */', $place['place']);
                $parent = array_reverse($parent);
                $parent_id = 0;
                for ($i = 0; $i < count($parent); $i++) {
                    if (!isset($default_zoom_level[$i])) {
                        $default_zoom_level[$i] = $default_zoom_level[$i - 1];
                    }
                    $escparent = $parent[$i];
                    if ($escparent == '') {
                        $escparent = 'Unknown';
                    }
                    $row = WT_DB::prepare("SELECT pl_id, pl_long, pl_lati, pl_zoom FROM `##placelocation` WHERE pl_level=? AND pl_parent_id=? AND pl_place LIKE ?")->execute(array($i, $parent_id, $escparent))->fetchOneRow();
                    if ($i < count($parent) - 1) {
                        // Create higher-level places, if necessary
                        if (empty($row)) {
                            $highestIndex++;
                            WT_DB::prepare("INSERT INTO `##placelocation` (pl_id, pl_parent_id, pl_level, pl_place, pl_zoom) VALUES (?, ?, ?, ?, ?)")->execute(array($highestIndex, $parent_id, $i, $escparent, $default_zoom_level[$i]));
                            echo WT_Filter::escapeHtml($escparent), '<br>';
                            $parent_id = $highestIndex;
                        } else {
                            $parent_id = $row->pl_id;
                        }
                    } else {
                        // Create lowest-level place, if necessary
                        if (empty($row->pl_id)) {
                            $highestIndex++;
                            WT_DB::prepare("INSERT INTO `##placelocation` (pl_id, pl_parent_id, pl_level, pl_place, pl_long, pl_lati, pl_zoom) VALUES (?, ?, ?, ?, ?, ?, ?)")->execute(array($highestIndex, $parent_id, $i, $escparent, $place['long'], $place['lati'], $default_zoom_level[$i]));
                            echo WT_Filter::escapeHtml($escparent), '<br>';
                        } else {
                            if (empty($row->pl_long) && empty($row->pl_lati) && $place['lati'] != '0' && $place['long'] != '0') {
                                WT_DB::prepare("UPDATE `##placelocation` SET pl_lati=?, pl_long=? WHERE pl_id=?")->execute(array($place['lati'], $place['long'], $row->pl_id));
                                echo WT_Filter::escapeHtml($escparent), '<br>';
                            }
                        }
                    }
                }
            }
            $parent = 0;
        }
        if ($action == 'ImportFile') {
            $placefiles = array();
            $this->findFiles(WT_MODULES_DIR . 'googlemap/extra');
            sort($placefiles);
            ?>
		<form method="post" enctype="multipart/form-data" id="importfile" name="importfile" action="module.php?mod=googlemap&amp;mod_action=admin_places&amp;action=ImportFile2">
			<table class="gm_plac_edit">
				<tr>
					<th><?php 
            echo WT_I18N::translate('File containing places (CSV)');
            ?>
</th>
					<td><input type="file" name="placesfile" size="50"></td>
				</tr>
				<?php 
            if (count($placefiles) > 0) {
                ?>
				<tr>
					<th><?php 
                echo WT_I18N::translate('Server file containing places (CSV)'), help_link('PLIF_LOCALFILE', 'googlemap');
                ?>
</th>
					<td>
						<select name="localfile">
							<option></option>
							<?php 
                foreach ($placefiles as $p => $placefile) {
                    ?>
							<option value="<?php 
                    echo WT_Filter::escapeHtml($placefile);
                    ?>
"><?php 
                    if (substr($placefile, 0, 1) == "/") {
                        echo substr($placefile, 1);
                    } else {
                        echo $placefile;
                    }
                    ?>
</option>
							<?php 
                }
                ?>
						</select>
					</td>
				</tr>
				<?php 
            }
            ?>
				<tr>
					<th><?php 
            echo WT_I18N::translate('Delete all existing geographic data before importing the file.');
            ?>
</th>
					<td><input type="checkbox" name="cleardatabase"></td>
				</tr>
				<tr>
					<th><?php 
            echo WT_I18N::translate('Do not create new locations, just import coordinates for existing locations.');
            ?>
</th>
					<td><input type="checkbox" name="updateonly"></td>
				</tr>
				<tr>
					<th><?php 
            echo WT_I18N::translate('Overwrite existing coordinates.');
            ?>
</th>
					<td><input type="checkbox" name="overwritedata"></td>
				</tr>
			</table>
			<input id="savebutton" type="submit" value="<?php 
            echo WT_I18N::translate('Continue adding');
            ?>
"><br>
		</form>
		<?php 
            exit;
        }
        if ($action == 'ImportFile2') {
            $country_names = array();
            foreach (WT_Stats::iso3166() as $key => $value) {
                $country_names[$key] = WT_I18N::translate($key);
            }
            if (isset($_POST['cleardatabase'])) {
                WT_DB::exec("DELETE FROM `##placelocation` WHERE 1=1");
            }
            if (!empty($_FILES['placesfile']['tmp_name'])) {
                $lines = file($_FILES['placesfile']['tmp_name']);
            } elseif (!empty($_REQUEST['localfile'])) {
                $lines = file(WT_MODULES_DIR . 'googlemap/extra' . $_REQUEST['localfile']);
            }
            // Strip BYTE-ORDER-MARK, if present
            if (!empty($lines[0]) && substr($lines[0], 0, 3) == WT_UTF8_BOM) {
                $lines[0] = substr($lines[0], 3);
            }
            asort($lines);
            $highestIndex = $this->getHighestIndex();
            $placelist = array();
            $j = 0;
            $maxLevel = 0;
            foreach ($lines as $p => $placerec) {
                $fieldrec = explode(';', $placerec);
                if ($fieldrec[0] > $maxLevel) {
                    $maxLevel = $fieldrec[0];
                }
            }
            $fields = count($fieldrec);
            $set_icon = true;
            if (!is_dir(WT_MODULES_DIR . 'googlemap/places/flags/')) {
                $set_icon = false;
            }
            foreach ($lines as $p => $placerec) {
                $fieldrec = explode(';', $placerec);
                if (is_numeric($fieldrec[0]) && $fieldrec[0] <= $maxLevel) {
                    $placelist[$j] = array();
                    $placelist[$j]['place'] = '';
                    for ($ii = $fields - 4; $ii > 1; $ii--) {
                        if ($fieldrec[0] > $ii - 2) {
                            $placelist[$j]['place'] .= $fieldrec[$ii] . ',';
                        }
                    }
                    foreach ($country_names as $countrycode => $countryname) {
                        if ($countrycode == strtoupper($fieldrec[1])) {
                            $fieldrec[1] = $countryname;
                            break;
                        }
                    }
                    $placelist[$j]['place'] .= $fieldrec[1];
                    $placelist[$j]['long'] = $fieldrec[$fields - 4];
                    $placelist[$j]['lati'] = $fieldrec[$fields - 3];
                    $placelist[$j]['zoom'] = $fieldrec[$fields - 2];
                    if ($set_icon) {
                        $placelist[$j]['icon'] = trim($fieldrec[$fields - 1]);
                    } else {
                        $placelist[$j]['icon'] = '';
                    }
                    $j = $j + 1;
                }
            }
            $prevPlace = '';
            $prevLati = '';
            $prevLong = '';
            $placelistUniq = array();
            $j = 0;
            foreach ($placelist as $k => $place) {
                if ($place['place'] != $prevPlace) {
                    $placelistUniq[$j] = array();
                    $placelistUniq[$j]['place'] = $place['place'];
                    $placelistUniq[$j]['lati'] = $place['lati'];
                    $placelistUniq[$j]['long'] = $place['long'];
                    $placelistUniq[$j]['zoom'] = $place['zoom'];
                    $placelistUniq[$j]['icon'] = $place['icon'];
                    $j = $j + 1;
                } elseif ($place['place'] == $prevPlace && ($place['lati'] != $prevLati || $place['long'] != $prevLong)) {
                    if ($placelistUniq[$j - 1]['lati'] == 0 || $placelistUniq[$j - 1]['long'] == 0) {
                        $placelistUniq[$j - 1]['lati'] = $place['lati'];
                        $placelistUniq[$j - 1]['long'] = $place['long'];
                        $placelistUniq[$j - 1]['zoom'] = $place['zoom'];
                        $placelistUniq[$j - 1]['icon'] = $place['icon'];
                    } elseif ($place['lati'] != '0' || $place['long'] != '0') {
                        echo 'Difference: previous value = ', $prevPlace, ', ', $prevLati, ', ', $prevLong, ' current = ', $place['place'], ', ', $place['lati'], ', ', $place['long'], '<br>';
                    }
                }
                $prevPlace = $place['place'];
                $prevLati = $place['lati'];
                $prevLong = $place['long'];
            }
            $default_zoom_level = array();
            $default_zoom_level[0] = 4;
            $default_zoom_level[1] = 7;
            $default_zoom_level[2] = 10;
            $default_zoom_level[3] = 12;
            foreach ($placelistUniq as $k => $place) {
                $parent = explode(',', $place['place']);
                $parent = array_reverse($parent);
                $parent_id = 0;
                for ($i = 0; $i < count($parent); $i++) {
                    $escparent = $parent[$i];
                    if ($escparent == '') {
                        $escparent = 'Unknown';
                    }
                    $row = WT_DB::prepare("SELECT pl_id, pl_long, pl_lati, pl_zoom, pl_icon FROM `##placelocation` WHERE pl_level=? AND pl_parent_id=? AND pl_place LIKE ? ORDER BY pl_place")->execute(array($i, $parent_id, $escparent))->fetchOneRow();
                    if (empty($row)) {
                        // this name does not yet exist: create entry
                        if (!isset($_POST['updateonly'])) {
                            $highestIndex = $highestIndex + 1;
                            if ($i + 1 == count($parent)) {
                                $zoomlevel = $place['zoom'];
                            } elseif (isset($default_zoom_level[$i])) {
                                $zoomlevel = $default_zoom_level[$i];
                            } else {
                                $zoomlevel = $this->getSetting('GM_MAX_ZOOM');
                            }
                            if ($place['lati'] == '0' || $place['long'] == '0' || $i + 1 < count($parent)) {
                                WT_DB::prepare("INSERT INTO `##placelocation` (pl_id, pl_parent_id, pl_level, pl_place, pl_zoom, pl_icon) VALUES (?, ?, ?, ?, ?, ?)")->execute(array($highestIndex, $parent_id, $i, $escparent, $zoomlevel, $place['icon']));
                            } else {
                                //delete leading zero
                                $pl_lati = str_replace(array('N', 'S', ','), array('', '-', '.'), $place['lati']);
                                $pl_long = str_replace(array('E', 'W', ','), array('', '-', '.'), $place['long']);
                                if ($pl_lati >= 0) {
                                    $place['lati'] = 'N' . abs($pl_lati);
                                } elseif ($pl_lati < 0) {
                                    $place['lati'] = 'S' . abs($pl_lati);
                                }
                                if ($pl_long >= 0) {
                                    $place['long'] = 'E' . abs($pl_long);
                                } elseif ($pl_long < 0) {
                                    $place['long'] = 'W' . abs($pl_long);
                                }
                                WT_DB::prepare("INSERT INTO `##placelocation` (pl_id, pl_parent_id, pl_level, pl_place, pl_long, pl_lati, pl_zoom, pl_icon) VALUES (?, ?, ?, ?, ?, ?, ?, ?)")->execute(array($highestIndex, $parent_id, $i, $escparent, $place['long'], $place['lati'], $zoomlevel, $place['icon']));
                            }
                            $parent_id = $highestIndex;
                        }
                    } else {
                        $parent_id = $row->pl_id;
                        if (isset($_POST['overwritedata']) && $i + 1 == count($parent)) {
                            WT_DB::prepare("UPDATE `##placelocation` SET pl_lati=?, pl_long=?, pl_zoom=?, pl_icon=? WHERE pl_id=?")->execute(array($place['lati'], $place['long'], $place['zoom'], $place['icon'], $parent_id));
                        } else {
                            if (($row->pl_long == '0' || $row->pl_long == null) && ($row->pl_lati == '0' || $row->pl_lati == null)) {
                                WT_DB::prepare("UPDATE `##placelocation` SET pl_lati=?, pl_long=? WHERE pl_id=?")->execute(array($place['lati'], $place['long'], $parent_id));
                            }
                            if (empty($row->pl_icon) && !empty($place['icon'])) {
                                WT_DB::prepare("UPDATE `##placelocation` SET pl_icon=? WHERE pl_id=?")->execute(array($place['icon'], $parent_id));
                            }
                        }
                    }
                }
            }
            $parent = 0;
        }
        if ($action == 'DeleteRecord') {
            $exists = WT_DB::prepare("SELECT 1 FROM `##placelocation` WHERE pl_parent_id=?")->execute(array($deleteRecord))->fetchOne();
            if (!$exists) {
                WT_DB::prepare("DELETE FROM `##placelocation` WHERE pl_id=?")->execute(array($deleteRecord));
            } else {
                echo '<table class="facts_table"><tr><td>', WT_I18N::translate('Location not removed: this location contains sub-locations'), '</td></tr></table>';
            }
        }
        ?>
		<script>
		function updateList(inactive) {
			window.location.href='<?php 
        if (strstr($_SERVER['REQUEST_URI'], '&inactive', true)) {
            $uri = strstr($_SERVER['REQUEST_URI'], '&inactive', true);
        } else {
            $uri = $_SERVER['REQUEST_URI'];
        }
        echo $uri, '&inactive=';
        ?>
'+inactive;
		}

		function edit_place_location(placeid) {
			window.open('module.php?mod=googlemap&mod_action=places_edit&action=update&placeid='+placeid, '_blank', gmap_window_specs);
			return false;
		}

		function add_place_location(placeid) {
			window.open('module.php?mod=googlemap&mod_action=places_edit&action=add&placeid='+placeid, '_blank', gmap_window_specs);
			return false;
		}

		function delete_place(placeid) {
			var answer=confirm('<?php 
        echo WT_I18N::translate('Remove this location?');
        ?>
');
			if (answer == true) {
				window.location = '<?php 
        echo $_SERVER['REQUEST_URI'];
        ?>
&action=DeleteRecord&deleteRecord=' + placeid;
			}
		}
		</script>
		<?php 
        echo '<div id="gm_breadcrumb">';
        $where_am_i = $this->placeIdToHierarchy($parent);
        foreach (array_reverse($where_am_i, true) as $id => $place) {
            if ($id == $parent) {
                if ($place != 'Unknown') {
                    echo WT_Filter::escapeHtml($place);
                } else {
                    echo WT_I18N::translate('unknown');
                }
            } else {
                echo '<a href="module.php?mod=googlemap&mod_action=admin_places&parent=', $id, '&inactive=', $inactive, '">';
                if ($place != 'Unknown') {
                    echo WT_Filter::escapeHtml($place), '</a>';
                } else {
                    echo WT_I18N::translate('unknown'), '</a>';
                }
            }
            echo ' - ';
        }
        echo '<a href="module.php?mod=googlemap&mod_action=admin_places&parent=0&inactive=', $inactive, '">', WT_I18N::translate('Top level'), '</a></div>';
        echo '<form name="active" method="post" action="module.php?mod=googlemap&mod_action=admin_places&parent=', $parent, '&inactive=', $inactive, '"><div id="gm_active">';
        echo '<label for="inactive">', WT_I18N::translate('Show inactive places'), '</label>';
        echo '<input type="checkbox" name="inactive" id="inactive"';
        if ($inactive) {
            echo ' checked="checked"';
        }
        echo ' onclick="updateList(this.checked)"';
        echo '>', help_link('PLE_ACTIVE', 'googlemap'), '</div></form>';
        $placelist = $this->getPlaceListLocation($parent, $inactive);
        echo '<div class="gm_plac_edit">';
        echo '<table class="gm_plac_edit"><tr>';
        echo '<th>', WT_Gedcom_Tag::getLabel('PLAC'), '</th>';
        echo '<th>', WT_Gedcom_Tag::getLabel('LATI'), '</th>';
        echo '<th>', WT_Gedcom_Tag::getLabel('LONG'), '</th>';
        echo '<th>', WT_I18N::translate('Zoom level'), '</th>';
        echo '<th>', WT_I18N::translate('Icon'), '</th>';
        echo '<th>';
        echo WT_I18N::translate('Edit'), '</th><th>', WT_I18N::translate('Delete'), '</th></tr>';
        if (count($placelist) == 0) {
            echo '<tr><td colspan="7" class="accepted">', WT_I18N::translate('No places found'), '</td></tr>';
        }
        foreach ($placelist as $place) {
            echo '<tr><td><a href="module.php?mod=googlemap&mod_action=admin_places&parent=', $place['place_id'], '&inactive=', $inactive, '">';
            if ($place['place'] != 'Unknown') {
                echo WT_Filter::escapeHtml($place['place']), '</a></td>';
            } else {
                echo WT_I18N::translate('unknown'), '</a></td>';
            }
            echo '<td>', $place['lati'], '</td>';
            echo '<td>', $place['long'], '</td>';
            echo '<td>', $place['zoom'], '</td>';
            echo '<td>';
            if ($place['icon'] == NULL || $place['icon'] == '') {
                if ($place['lati'] == NULL || $place['long'] == NULL || $place['lati'] == '0' && $place['long'] == '0') {
                    echo '<img src="', WT_STATIC_URL, WT_MODULES_DIR, 'googlemap/images/mm_20_yellow.png">';
                } else {
                    echo '<img src="', WT_STATIC_URL, WT_MODULES_DIR, 'googlemap/images/mm_20_red.png">';
                }
            } else {
                echo '<img src="', WT_STATIC_URL, WT_MODULES_DIR, 'googlemap/', $place['icon'], '" width="25" height="15">';
            }
            echo '</td>';
            echo '<td class="narrow"><a href="#" onclick="edit_place_location(', $place['place_id'], ');return false;" class="icon-edit" title="', WT_I18N::translate('Edit'), '"></a></td>';
            $noRows = WT_DB::prepare("SELECT COUNT(pl_id) FROM `##placelocation` WHERE pl_parent_id=?")->execute(array($place['place_id']))->fetchOne();
            if ($noRows == 0) {
                ?>
				<td><a href="#" onclick="delete_place(<?php 
                echo $place['place_id'];
                ?>
);return false;" class="icon-delete" title="<?php 
                echo WT_I18N::translate('Remove');
                ?>
"></a></td>
		<?php 
            } else {
                ?>
				<td><i class="icon-delete-grey"></i></td>
		<?php 
            }
            ?>
			</tr>
			<?php 
        }
        ?>
		</table>
		</div>

		<table id="gm_manage">
			<tr>
				<td>
					<?php 
        echo WT_I18N::translate('Add  a new geographic location');
        ?>
				</td>
				<td>
					<form action="?" onsubmit="add_place_location(this.parent_id.options[this.parent_id.selectedIndex].value); return false;">
						<?php 
        echo select_edit_control('parent_id', $where_am_i, WT_I18N::translate('Top level'), $parent);
        ?>
						<input type="submit" value="<?php 
        echo WT_I18N::translate('Add');
        ?>
">
					</form>
				</td>
			</tr>
			<tr>
				<td>
					<?php 
        echo WT_I18N::translate('Import all places from a family tree');
        ?>
				</td>
				<td>
					<form action="module.php" method="get">
						<input type="hidden" name="mod" value="googlemap">
						<input type="hidden" name="mod_action" value="admin_places">
						<input type="hidden" name="action" value="ImportGedcom">
						<?php 
        echo select_edit_control('ged', WT_Tree::getNameList(), null, WT_GEDCOM);
        ?>
						<input type="submit" value="<?php 
        echo WT_I18N::translate('Import');
        ?>
">
					</form>
				</td>
			</tr>
			<tr>
				<td>
					<?php 
        echo WT_I18N::translate('Upload geographic data');
        ?>
				</td>
				<td>
					<form action="module.php" method="get">
						<input type="hidden" name="mod" value="googlemap">
						<input type="hidden" name="mod_action" value="admin_places">
						<input type="hidden" name="action" value="ImportFile">
						<input type="submit" value="<?php 
        echo WT_I18N::translate('Upload');
        ?>
">
					</form>
				</td>
			</tr>
			<tr>
				<td>
					<?php 
        echo WT_I18N::translate('Download geographic data');
        ?>
				</td>
				<td>
					<form action="module.php" method="get">
						<input type="hidden" name="mod" value="googlemap">
						<input type="hidden" name="mod_action" value="admin_places">
						<input type="hidden" name="action" value="ExportFile">
						<?php 
        echo select_edit_control('parent', $where_am_i, WT_I18N::translate('All'), WT_GED_ID);
        ?>
						<input type="submit" value="<?php 
        echo WT_I18N::translate('Download');
        ?>
">
					</form>
				</td>
			</tr>
		</table>
		<?php 
    }
Ejemplo n.º 20
0
echo '<p>pgv_messages => wt_message ...</p>';
ob_flush();
flush();
usleep(50000);
WT_DB::prepare("REPLACE INTO `##message` (message_id, sender, ip_address, user_id, subject, body, created)" . " SELECT m_id, m_from, '127.0.0.1', user_id, m_subject, m_body, str_to_date(m_created,'%a, %d %M %Y %H:%i:%s')" . " FROM `{$DBNAME}`.`{$TBLPREFIX}messages`" . " JOIN `##user` ON (CONVERT(m_to USING utf8) COLLATE utf8_unicode_ci=user_name)")->execute();
////////////////////////////////////////////////////////////////////////////////
try {
    echo '<p>pgv_placelocation => wt_placelocation ...</p>';
    ob_flush();
    flush();
    usleep(50000);
    WT_DB::prepare("REPLACE INTO `##placelocation` (pl_id, pl_parent_id, pl_level, pl_place, pl_long, pl_lati, pl_zoom, pl_icon)" . " SELECT pl_id, pl_parent_id, pl_level, pl_place, pl_long, pl_lati, pl_zoom, pl_icon FROM `{$DBNAME}`.`{$TBLPREFIX}placelocation`")->execute();
} catch (PDOexception $ex) {
    // This table will only exist if the gm module is installed in PGV/WT
}
////////////////////////////////////////////////////////////////////////////////
echo '<p>Genealogy records ...</p>';
ob_flush();
flush();
usleep(50000);
WT_DB::prepare("INSERT INTO `##gedcom_chunk` (gedcom_id, chunk_data, imported)" . " SELECT o_file, o_gedcom, 0 FROM `{$DBNAME}`.`{$TBLPREFIX}other`" . " JOIN `##gedcom` ON (o_file = gedcom_id)" . " ORDER BY o_type!='HEAD'")->execute();
WT_DB::prepare("INSERT INTO `##gedcom_chunk` (gedcom_id, chunk_data, imported)" . " SELECT i_file, i_gedcom, 0 FROM `{$DBNAME}`.`{$TBLPREFIX}individuals`" . " JOIN `##gedcom` ON (i_file = gedcom_id)")->execute();
WT_DB::prepare("INSERT INTO `##gedcom_chunk` (gedcom_id, chunk_data, imported)" . " SELECT f_file, f_gedcom, 0 FROM `{$DBNAME}`.`{$TBLPREFIX}families`" . " JOIN `##gedcom` ON (f_file = gedcom_id)")->execute();
WT_DB::prepare("INSERT INTO `##gedcom_chunk` (gedcom_id, chunk_data, imported)" . " SELECT s_file, s_gedcom, 0 FROM `{$DBNAME}`.`{$TBLPREFIX}sources`" . " JOIN `##gedcom` ON (s_file = gedcom_id)")->execute();
WT_DB::prepare("INSERT INTO `##gedcom_chunk` (gedcom_id, chunk_data, imported)" . " SELECT m_gedfile, m_gedrec, 0 FROM `{$DBNAME}`.`{$TBLPREFIX}media`" . " JOIN `##gedcom` ON (m_gedfile = gedcom_id)")->execute();
WT_DB::prepare("UPDATE `##gedcom_setting` SET setting_value='0' WHERE setting_name='imported'")->execute();
////////////////////////////////////////////////////////////////////////////////
WT_DB::exec("COMMIT");
echo '<hr>';
echo '<p>', WT_I18N::translate('You need to login again, using your PhpGedView username and password.'), '</p>';
echo '<a href="index.php"><button>', WT_I18N::translate('continue'), '</button></a>';
Ejemplo n.º 21
0
    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>
Ejemplo n.º 22
0
 private static function search_indis_year_range($startyear, $endyear)
 {
     // At present, the lifespan chart is driven by Gregorian years.
     // We ought to allow it to work with other calendars...
     $gregorian_calendar = new GregorianCalendar();
     $startjd = $gregorian_calendar->ymdToJd($startyear, 1, 1);
     $endjd = $gregorian_calendar->ymdToJd($endyear, 12, 31);
     $sql = "SELECT DISTINCT i_id AS xref, i_file AS gedcom_id, i_gedcom AS gedcom" . " FROM `##individuals`" . " JOIN `##dates` ON i_id=d_gid AND i_file=d_file" . " WHERE i_file=? AND d_julianday1 BETWEEN ? AND ?";
     $rows = WT_DB::prepare($sql)->execute(array(WT_GED_ID, $startjd, $endjd))->fetchAll();
     $list = array();
     foreach ($rows as $row) {
         $list[] = WT_Individual::getInstance($row->xref, $row->gedcom_id, $row->gedcom);
     }
     return $list;
 }
Ejemplo n.º 23
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;
 }
Ejemplo n.º 24
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;
     }
 }
Ejemplo n.º 25
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;
    }
}
Ejemplo n.º 26
0
                WT_DB::prepare("UPDATE `##media` JOIN `##link` ON (l_file = m_file AND l_to = ?) SET m_gedcom = REPLACE(m_gedcom, ?, ?) WHERE m_file = ?")->execute(array($old_xref, " @{$old_xref}@", " @{$new_xref}@", WT_GED_ID));
                WT_DB::prepare("UPDATE `##sources` JOIN `##link` ON (l_file = s_file AND l_to = ?) SET s_gedcom = REPLACE(s_gedcom, ?, ?) WHERE s_file = ?")->execute(array($old_xref, " @{$old_xref}@", " @{$new_xref}@", WT_GED_ID));
                WT_DB::prepare("UPDATE `##other` JOIN `##link` ON (l_file = o_file AND l_to = ?) SET o_gedcom = REPLACE(o_gedcom, ?, ?) WHERE o_file = ?")->execute(array($old_xref, " @{$old_xref}@", " @{$new_xref}@", WT_GED_ID));
                break;
        }
        WT_DB::prepare("UPDATE `##name` SET n_id = ? WHERE n_id = ? AND n_file = ?")->execute(array($new_xref, $old_xref, WT_GED_ID));
        WT_DB::prepare("UPDATE `##default_resn` SET xref = ? WHERE xref = ? AND gedcom_id = ?")->execute(array($new_xref, $old_xref, WT_GED_ID));
        WT_DB::prepare("UPDATE `##hit_counter` SET page_parameter = ? WHERE page_parameter = ? AND gedcom_id = ?")->execute(array($new_xref, $old_xref, WT_GED_ID));
        WT_DB::prepare("UPDATE `##link` SET l_from = ? WHERE l_from = ? AND l_file = ?")->execute(array($new_xref, $old_xref, WT_GED_ID));
        WT_DB::prepare("UPDATE `##link` SET l_to = ? WHERE l_to = ? AND l_file = ?")->execute(array($new_xref, $old_xref, WT_GED_ID));
        echo '<p>', WT_I18N::translate('The record %1$s was renamed to %2$s.', $old_xref, $new_xref), '</p>';
        unset($xrefs[$old_xref]);
        WT_DB::exec("UNLOCK TABLES");
        WT_DB::exec("COMMIT");
        try {
            WT_DB::prepare("UPDATE `##favorite` SET xref = ? WHERE xref = ? AND gedcom_id = ?")->execute(array($new_xref, $old_xref, WT_GED_ID));
        } catch (Exception $ex) {
            // Perhaps the favorites module was not installed?
        }
        // How much time do we have left?
        if (microtime(true) - $start_time > ini_get('max_execution_time') - 5) {
            echo '<p>', WT_I18N::translate('The server’s time limit was reached.'), '</p>';
            break;
        }
    }
    if ($xrefs) {
    }
} else {
    echo '<p>', WT_I18N::translate('In a family tree, each record has an internal reference number (called an “XREF”) such as “F123” or "R14".'), '</p>';
    echo '<p>', WT_I18N::translate('You can renumber a family tree so that these reference numbers are unique across all family trees.'), '</p>';
}
Ejemplo n.º 27
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();
 }
Ejemplo n.º 28
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;
        }
    }
Ejemplo n.º 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>';
Ejemplo n.º 30
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;
             }
         }
     }
 }