Example #1
0
 /**
  * Upgrade to to the next version
  */
 public function upgrade()
 {
     $index_dir = Site::getPreference('INDEX_DIRECTORY');
     // Due to the language code changes in 1.7.0, we need to update some other settings
     foreach ($this->languages as $old => $new) {
         try {
             Database::prepare("UPDATE `##site_setting` SET setting_name = REPLACE(setting_name, :old, :new) " . "WHERE setting_name LIKE 'WELCOME_TEXT_AUTH_MODE_%'")->execute(array('old' => $old, 'new' => $new));
         } catch (PDOException $ex) {
             // Duplicate key? Already done?
         }
         Database::prepare("UPDATE `##block_setting` SET setting_value = REPLACE(setting_value, :old, :new) " . "WHERE setting_name = 'languages'")->execute(array('old' => $old, 'new' => $new));
         // Historical fact files
         if (file_exists($index_dir . 'histo.' . $old . '.php') && !file_exists($index_dir . 'histo.' . $new . '.php')) {
             rename($index_dir . 'histo.' . $old . '.php', $index_dir . 'histo.' . $new . '.php');
         }
         // Language files
         if (file_exists($index_dir . 'language/' . $old . '.php') && !file_exists($index_dir . 'language/' . $new . '.php')) {
             rename($index_dir . 'language/' . $old . '.php', $index_dir . 'language/' . $new . '.php');
         }
         if (file_exists($index_dir . 'language/' . $old . '.csv') && !file_exists($index_dir . 'language/' . $new . '.csv')) {
             rename($index_dir . 'language/' . $old . '.csv', $index_dir . 'language/' . $new . '.csv');
         }
         if (file_exists($index_dir . 'language/' . $old . '.mo') && !file_exists($index_dir . 'language/' . $new . '.mo')) {
             rename($index_dir . 'language/' . $old . '.mo', $index_dir . 'language/' . $new . '.mo');
         }
     }
 }
Example #2
0
 /** {@inheritDoc} */
 public function upgrade()
 {
     $module_options = 'FTV_OPTIONS';
     $ftv_options = Database::prepare("SELECT setting_value FROM `##module_setting` WHERE setting_name=?")->execute(array($module_options))->fetchOne();
     $options = unserialize($ftv_options);
     if (!empty($options)) {
         foreach ($options as $option) {
             foreach ($option as $key => $value) {
                 if ($key == 'USE_FTV_THUMBS') {
                     $option['RESIZE_THUMBS'] = $value;
                     unset($option[$key]);
                 }
                 if ($key == 'COUNTRY') {
                     unset($option[$key]);
                 }
             }
             $option['USE_GEDCOM_PLACES'] = '1';
             $option['THUMB_RESIZE_FORMAT'] = '2';
             $new_options[] = $option;
         }
         if (isset($new_options)) {
             Database::prepare("UPDATE `##module_setting` SET setting_value=? WHERE setting_name=?")->execute(array(serialize($new_options), $module_options));
         }
         unset($new_options);
     }
 }
Example #3
0
 /** {@inheritDoc} */
 public function upgrade()
 {
     // add key 'LINK' to FTV_SETTINGS
     // change options to multidimensional array with array key = tree id.
     $module_settings = 'FTV_SETTINGS';
     $ftv_settings = Database::prepare("SELECT setting_value FROM `##module_setting` WHERE setting_name=?")->execute(array($module_settings))->fetchOne();
     $settings = unserialize($ftv_settings);
     if (!empty($settings)) {
         foreach ($settings as $setting) {
             if (!array_key_exists('LINK', $setting)) {
                 $setting['LINK'] = I18N::translate('Descendants of the %s family', $setting['SURNAME']);
                 $new_settings[] = $setting;
             }
         }
         if (isset($new_settings)) {
             Database::prepare("UPDATE `##module_setting` SET setting_value=? WHERE setting_name=?")->execute(array(serialize($new_settings), $module_settings));
         }
         unset($new_settings);
     }
     $module_options = 'FTV_OPTIONS';
     $ftv_options = Database::prepare("SELECT setting_value FROM `##module_setting` WHERE setting_name=?")->execute(array($module_options))->fetchOne();
     $options = unserialize($ftv_options);
     if (!empty($options)) {
         $show_places = array_key_exists('SHOW_PLACES', $options) ? $options['SHOW_PLACES'] : '1';
         $country = array_key_exists('COUNTRY', $options) ? $options['COUNTRY'] : '';
         $show_occu = array_key_exists('SHOW_OCCU', $options) ? $options['SHOW_OCCU'] : '1';
         foreach (Tree::getAll() as $tree) {
             $new_options[$tree->getTreeId()] = array('SHOW_PLACES' => $show_places, 'COUNTRY' => $country, 'SHOW_OCCU' => $show_occu);
         }
         if (isset($new_options)) {
             Database::prepare("UPDATE `##module_setting` SET setting_value=? WHERE setting_name=?")->execute(array(serialize($new_options), $module_options));
         }
         unset($new_options);
     }
 }
Example #4
0
 /**
  * Upgrade to to the next version
  */
 public function upgrade()
 {
     try {
         Database::prepare("ALTER TABLE `##site_setting` CHANGE setting_value setting_value VARCHAR(2000) NOT NULL")->execute();
     } catch (PDOException $ex) {
         // Already done?
     }
 }
Example #5
0
 /**
  * Upgrade to to the next version
  */
 public function upgrade()
 {
     try {
         Database::prepare("ALTER TABLE `##site_setting` CHANGE setting_value setting_value VARCHAR(2000) NOT NULL")->execute();
     } catch (PDOException $ex) {
         // Already done?
     }
     Database::prepare("DELETE FROM `##change` WHERE old_gedcom = '' AND new_gedcom = ''")->execute();
 }
 /**
  * {@inheritDoc}
  * @see \MyArtJaub\Webtrees\Map\MapProviderInterface::getPlaceIcon()
  */
 public function getPlaceIcon(\Fisharebest\Webtrees\Place $place)
 {
     if (!$place->isEmpty()) {
         $place_details = Database::prepare('SELECT SQL_CACHE pl_icon FROM `##placelocation` WHERE pl_id=? ORDER BY pl_place')->execute(array($this->getProviderPlaceId($place)))->fetchOneRow();
         if ($place_details) {
             return WT_MODULES_DIR . 'googlemap/' . $place_details->pl_icon;
         }
     }
     return null;
 }
 /**
  * Generate the HTML content of this block.
  *
  * @param int      $block_id
  * @param bool     $template
  * @param string[] $cfg
  *
  * @return string
  */
 public function getBlock($block_id, $template = true, $cfg = array())
 {
     global $ctype, $WT_TREE;
     $num = $this->getBlockSetting($block_id, 'num', '10');
     $count_placement = $this->getBlockSetting($block_id, 'count_placement', 'before');
     $block = $this->getBlockSetting($block_id, 'block', '0');
     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' && Auth::isManager($WT_TREE) || $ctype === 'user' && Auth::check()) {
         $title = '<a class="icon-admin" title="' . I18N::translate('Configure') . '" href="block_edit.php?block_id=' . $block_id . '&amp;ged=' . $WT_TREE->getNameHtml() . '&amp;ctype=' . $ctype . '"></a>';
     } else {
         $title = '';
     }
     $title .= $this->getTitle();
     $content = '';
     // load the lines from the file
     $top10 = Database::prepare("SELECT page_parameter, page_count" . " FROM `##hit_counter`" . " WHERE gedcom_id = :tree_id AND page_name IN ('individual.php','family.php','source.php','repo.php','note.php','mediaviewer.php')" . " ORDER BY page_count DESC LIMIT :limit")->execute(array('tree_id' => $WT_TREE->getTreeId(), 'limit' => (int) $num))->fetchAssoc();
     if ($block) {
         $content .= '<table width="90%">';
     } else {
         $content .= '<table>';
     }
     foreach ($top10 as $id => $count) {
         $record = GedcomRecord::getInstance($id, $WT_TREE);
         if ($record && $record->canShow()) {
             $content .= '<tr>';
             if ($count_placement == 'before') {
                 $content .= '<td dir="ltr" style="text-align:right">[' . $count . ']</td>';
             }
             $content .= '<td class="name2" ><a href="' . $record->getHtmlUrl() . '">' . $record->getFullName() . '</a></td>';
             if ($count_placement == 'after') {
                 $content .= '<td dir="ltr" style="text-align:right">[' . $count . ']</td>';
             }
             $content .= '</tr>';
         }
     }
     $content .= "</table>";
     if ($template) {
         if ($block) {
             $class .= ' small_inner_block';
         }
         return Theme::theme()->formatBlock($id, $title, $class, $content);
     } else {
         return $content;
     }
 }
Example #8
0
 /**
  * Upgrade to to the next version
  */
 public function upgrade()
 {
     // - data update for 1.4.0 media changes
     $_cfgs = Database::prepare("SELECT gs1.gedcom_id AS gedcom_id, gs1.setting_value AS media_directory, gs2.setting_value AS use_media_firewall, gs3.setting_value AS media_firewall_thumbs, gs4.setting_value AS media_firewall_rootdir" . " FROM `##gedcom_setting` gs1" . " LEFT JOIN `##gedcom_setting` gs2 ON (gs1.gedcom_id = gs2.gedcom_id AND gs2.setting_name='USE_MEDIA_FIREWALL')" . " LEFT JOIN `##gedcom_setting` gs3 ON (gs1.gedcom_id = gs3.gedcom_id AND gs3.setting_name='MEDIA_FIREWALL_THUMBS')" . " LEFT JOIN `##gedcom_setting` gs4 ON (gs1.gedcom_id = gs4.gedcom_id AND gs4.setting_name='MEDIA_FIREWALL_ROOTDIR')" . " WHERE gs1.setting_name = 'MEDIA_DIRECTORY'")->fetchAll();
     // The constant WT_DATA_DIR is not defined yet (although it was when this script was originally written).
     $WT_DATA_DIR = realpath('data');
     // Check the config for each tree
     foreach ($_cfgs as $_cfg) {
         if ($_cfg->use_media_firewall) {
             // We’re using the media firewall.
             $_mf_dir = realpath($_cfg->media_firewall_rootdir) . DIRECTORY_SEPARATOR;
             if ($_mf_dir == $WT_DATA_DIR) {
                 // We’re already storing our media in the data folder - nothing to do.
             } else {
                 // We’ve chosen a custom location for our media folder - need to update our media-folder to point to it.
                 // We have, for example,
                 // $_mf_dir = /home/fisharebest/my_pictures/
                 // $WT_DATA_DIR = /home/fisharebest/public_html/webtrees/data/
                 // Therefore we need to calculate ../../../my_pictures/
                 $_media_dir = '';
                 $_tmp_dir = $WT_DATA_DIR;
                 while (strpos($_mf_dir, $_tmp_dir) !== 0) {
                     $_media_dir .= '../';
                     $_tmp_dir = preg_replace('~[^/\\\\]+[/\\\\]$~', '', $_tmp_dir);
                     if ($_tmp_dir == '') {
                         // Shouldn't get here - but this script is not allowed to fail...
                         continue 2;
                     }
                 }
                 $_media_dir .= $_cfg->media_directory;
                 Database::prepare("UPDATE `##gedcom_setting`" . " SET setting_value=?" . " WHERE gedcom_id=? AND setting_name='MEDIA_DIRECTORY'")->execute(array($_media_dir, $_cfg->gedcom_id));
             }
         } else {
             // Not using the media firewall - just move the public folder to the new location (if we can).
             if (file_exists(WT_ROOT . $_cfg->media_directory) && is_dir(WT_ROOT . $_cfg->media_directory) && !file_exists($WT_DATA_DIR . $_cfg->media_directory)) {
                 try {
                     rename(WT_ROOT . $_cfg->media_directory, $WT_DATA_DIR . $_cfg->media_directory);
                 } catch (\ErrorException $ex) {
                     // Cannot move the folder?
                 }
                 File::delete($WT_DATA_DIR . $_cfg->media_directory . '.htaccess');
                 File::delete($WT_DATA_DIR . $_cfg->media_directory . 'index.php');
                 File::delete($WT_DATA_DIR . $_cfg->media_directory . 'Mediainfo.txt');
                 File::delete($WT_DATA_DIR . $_cfg->media_directory . 'thumbs/Thumbsinfo.txt');
             }
         }
     }
     // Delete old settings
     Database::exec("DELETE FROM `##gedcom_setting` WHERE setting_name IN ('USE_MEDIA_FIREWALL', 'MEDIA_FIREWALL_THUMBS', 'MEDIA_FIREWALL_ROOTDIR')");
 }
Example #9
0
 /**
  * Upgrade to to the next version
  */
 public function upgrade()
 {
     $WEBTREES_EMAIL = 'webtrees-noreply@' . preg_replace('/^www\\./i', '', Filter::server('SERVER_NAME'));
     // Default settings for new trees.  No defaults for:
     // imported, title, CONTACT_USER_ID, WEBMASTER_USER_ID
     // The following settings have defaults, but may need overwriting:
     // LANGUAGE, SURNAME_TRADITION
     Database::prepare("INSERT IGNORE INTO `##gedcom_setting` (gedcom_id, setting_name, setting_value) VALUES" . "(-1, 'ADVANCED_NAME_FACTS', 'NICK,_AKA')," . "(-1, 'ADVANCED_PLAC_FACTS', '')," . "(-1, 'ALLOW_THEME_DROPDOWN', '1')," . "(-1, 'CALENDAR_FORMAT', 'gregorian')," . "(-1, 'CHART_BOX_TAGS', '')," . "(-1, 'COMMON_NAMES_ADD', '')," . "(-1, 'COMMON_NAMES_REMOVE', '')," . "(-1, 'COMMON_NAMES_THRESHOLD', '40')," . "(-1, 'DEFAULT_PEDIGREE_GENERATIONS', '4')," . "(-1, 'EXPAND_RELATIVES_EVENTS', '0')," . "(-1, 'EXPAND_SOURCES', '0')," . "(-1, 'FAM_FACTS_ADD', 'CENS,MARR,RESI,SLGS,MARR_CIVIL,MARR_RELIGIOUS,MARR_PARTNERS,RESN')," . "(-1, 'FAM_FACTS_QUICK', 'MARR,DIV,_NMR')," . "(-1, 'FAM_FACTS_UNIQUE', 'NCHI,MARL,DIV,ANUL,DIVF,ENGA,MARB,MARC,MARS')," . "(-1, 'FAM_ID_PREFIX', 'F')," . "(-1, 'FORMAT_TEXT', 'markdown')," . "(-1, 'FULL_SOURCES', '0')," . "(-1, 'GEDCOM_ID_PREFIX', 'I')," . "(-1, 'GEDCOM_MEDIA_PATH', '')," . "(-1, 'GENERATE_UIDS', '0')," . "(-1, 'HIDE_GEDCOM_ERRORS', '1')," . "(-1, 'HIDE_LIVE_PEOPLE', '1')," . "(-1, 'INDI_FACTS_ADD', 'AFN,BIRT,DEAT,BURI,CREM,ADOP,BAPM,BARM,BASM,BLES,CHRA,CONF,FCOM,ORDN,NATU,EMIG,IMMI,CENS,PROB,WILL,GRAD,RETI,DSCR,EDUC,IDNO,NATI,NCHI,NMR,OCCU,PROP,RELI,RESI,SSN,TITL,BAPL,CONL,ENDL,SLGC,_MILI,ASSO,RESN')," . "(-1, 'INDI_FACTS_QUICK', 'BIRT,BURI,BAPM,CENS,DEAT,OCCU,RESI')," . "(-1, 'INDI_FACTS_UNIQUE', '')," . "(-1, 'KEEP_ALIVE_YEARS_BIRTH', '')," . "(-1, 'KEEP_ALIVE_YEARS_DEATH', '')," . "(-1, 'LANGUAGE', 'en-US')," . "(-1, 'MAX_ALIVE_AGE', '120')," . "(-1, 'MAX_DESCENDANCY_GENERATIONS', '15')," . "(-1, 'MAX_PEDIGREE_GENERATIONS', '10')," . "(-1, 'MEDIA_DIRECTORY', 'media/')," . "(-1, 'MEDIA_ID_PREFIX', 'M')," . "(-1, 'MEDIA_UPLOAD', :MEDIA_UPLOAD)," . "(-1, 'META_DESCRIPTION', '')," . "(-1, 'META_TITLE', :META_TITLE)," . "(-1, 'NOTE_FACTS_ADD', 'SOUR,RESN')," . "(-1, 'NOTE_FACTS_QUICK', '')," . "(-1, 'NOTE_FACTS_UNIQUE', '')," . "(-1, 'NOTE_ID_PREFIX', 'N')," . "(-1, 'NO_UPDATE_CHAN', '0')," . "(-1, 'PEDIGREE_FULL_DETAILS', '1')," . "(-1, 'PEDIGREE_LAYOUT', '1')," . "(-1, 'PEDIGREE_ROOT_ID', '')," . "(-1, 'PEDIGREE_SHOW_GENDER', '0')," . "(-1, 'PREFER_LEVEL2_SOURCES', '1')," . "(-1, 'QUICK_REQUIRED_FACTS', 'BIRT,DEAT')," . "(-1, 'QUICK_REQUIRED_FAMFACTS', 'MARR')," . "(-1, 'REPO_FACTS_ADD', 'PHON,EMAIL,FAX,WWW,RESN')," . "(-1, 'REPO_FACTS_QUICK', '')," . "(-1, 'REPO_FACTS_UNIQUE', 'NAME,ADDR')," . "(-1, 'REPO_ID_PREFIX', 'R')," . "(-1, 'REQUIRE_AUTHENTICATION', '0')," . "(-1, 'SAVE_WATERMARK_IMAGE', '0')," . "(-1, 'SAVE_WATERMARK_THUMB', '0')," . "(-1, 'SHOW_AGE_DIFF', '0')," . "(-1, 'SHOW_COUNTER', '1')," . "(-1, 'SHOW_DEAD_PEOPLE', :SHOW_DEAD_PEOPLE)," . "(-1, 'SHOW_EST_LIST_DATES', '0')," . "(-1, 'SHOW_FACT_ICONS', '1')," . "(-1, 'SHOW_GEDCOM_RECORD', '0')," . "(-1, 'SHOW_HIGHLIGHT_IMAGES', '1')," . "(-1, 'SHOW_LDS_AT_GLANCE', '0')," . "(-1, 'SHOW_LEVEL2_NOTES', '1')," . "(-1, 'SHOW_LIVING_NAMES', :SHOW_LIVING_NAMES)," . "(-1, 'SHOW_MEDIA_DOWNLOAD', '0')," . "(-1, 'SHOW_NO_WATERMARK', :SHOW_NO_WATERMARK)," . "(-1, 'SHOW_PARENTS_AGE', '1')," . "(-1, 'SHOW_PEDIGREE_PLACES', '9')," . "(-1, 'SHOW_PEDIGREE_PLACES_SUFFIX', '0')," . "(-1, 'SHOW_PRIVATE_RELATIONSHIPS', '1')," . "(-1, 'SHOW_RELATIVES_EVENTS', '_BIRT_CHIL,_BIRT_SIBL,_MARR_CHIL,_MARR_PARE,_DEAT_CHIL,_DEAT_PARE,_DEAT_GPAR,_DEAT_SIBL,_DEAT_SPOU')," . "(-1, 'SOURCE_ID_PREFIX', 'S')," . "(-1, 'SOUR_FACTS_ADD', 'NOTE,REPO,SHARED_NOTE,RESN')," . "(-1, 'SOUR_FACTS_QUICK', 'TEXT,NOTE,REPO')," . "(-1, 'SOUR_FACTS_UNIQUE', 'AUTH,ABBR,TITL,PUBL,TEXT')," . "(-1, 'SUBLIST_TRIGGER_I', '200')," . "(-1, 'SURNAME_LIST_STYLE', 'style2')," . "(-1, 'SURNAME_TRADITION', 'paternal')," . "(-1, 'THUMBNAIL_WIDTH', '100')," . "(-1, 'USE_RIN', '0')," . "(-1, 'USE_SILHOUETTE', '1')," . "(-1, 'WATERMARK_THUMB', '0')," . "(-1, 'WEBTREES_EMAIL', :WEBTREES_EMAIL)," . "(-1, 'WORD_WRAPPED_NOTES', '0')")->execute(array('MEDIA_UPLOAD' => Auth::PRIV_USER, 'META_TITLE' => WT_WEBTREES, 'SHOW_DEAD_PEOPLE' => Auth::PRIV_PRIVATE, 'SHOW_LIVING_NAMES' => Auth::PRIV_USER, 'SHOW_NO_WATERMARK' => Auth::PRIV_USER, 'WEBTREES_EMAIL' => $WEBTREES_EMAIL));
     // Previous versions of webtrees allowed this setting to be empty.
     Database::prepare("DELETE FROM `##gedcom_setting` WHERE setting_name  ='WEBTREES_EMAIL' AND setting_value = ''")->execute();
     Database::prepare("INSERT IGNORE INTO `##gedcom_setting` (gedcom_id, setting_name, setting_value)" . " SELECT gedcom_id, 'WEBTREES_EMAIL', :WEBTREES_EMAIL" . " FROM `##gedcom` WHERE gedcom_id > 0")->execute(array('WEBTREES_EMAIL' => $WEBTREES_EMAIL));
     // Default restrictions
     Database::prepare("INSERT IGNORE INTO `##default_resn` (gedcom_id, tag_type, resn) VALUES " . "(-1, 'SSN', 'confidential')," . "(-1, 'SOUR', 'privacy')," . "(-1, 'REPO', 'privacy')," . "(-1, 'SUBM', 'confidential')," . "(-1, 'SUBN', 'confidential')")->execute();
 }
 /**
  * Generate the HTML content of this block.
  *
  * @param int      $block_id
  * @param bool     $template
  * @param string[] $cfg
  *
  * @return string
  */
 public function getBlock($block_id, $template = true, $cfg = array())
 {
     global $ctype, $WT_TREE;
     switch (Filter::get('action')) {
         case 'deletenews':
             $news_id = Filter::getInteger('news_id');
             if ($news_id) {
                 Database::prepare("DELETE FROM `##news` WHERE news_id = ?")->execute(array($news_id));
             }
             break;
     }
     $block = $this->getBlockSetting($block_id, 'block', '1');
     foreach (array('block') as $name) {
         if (array_key_exists($name, $cfg)) {
             ${$name} = $cfg[$name];
         }
     }
     $usernews = Database::prepare("SELECT SQL_CACHE news_id, user_id, gedcom_id, UNIX_TIMESTAMP(updated) AS updated, subject, body FROM `##news` WHERE user_id = ? ORDER BY updated DESC")->execute(array(Auth::id()))->fetchAll();
     $id = $this->getName() . $block_id;
     $class = $this->getName() . '_block';
     $title = '';
     $title .= $this->getTitle();
     $content = '';
     if (!$usernews) {
         $content .= I18N::translate('You have not created any journal items.');
     }
     foreach ($usernews as $news) {
         $content .= '<div class="journal_box">';
         $content .= '<div class="news_title">' . $news->subject . '</div>';
         $content .= '<div class="news_date">' . FunctionsDate::formatTimestamp($news->updated) . '</div>';
         if ($news->body == strip_tags($news->body)) {
             // No HTML?
             $news->body = nl2br($news->body, false);
         }
         $content .= $news->body . '<br><br>';
         $content .= '<a href="#" onclick="window.open(\'editnews.php?news_id=\'+' . $news->news_id . ', \'_blank\', indx_window_specs); return false;">' . I18N::translate('Edit') . '</a> | ';
         $content .= '<a href="index.php?action=deletenews&amp;news_id=' . $news->news_id . '&amp;ctype=' . $ctype . '&amp;ged=' . $WT_TREE->getNameHtml() . '" onclick="return confirm(\'' . I18N::translate('Are you sure you want to delete “%s”?', Filter::escapeHtml($news->subject)) . "');\">" . I18N::translate('Delete') . '</a><br>';
         $content .= "</div><br>";
     }
     $content .= '<br><a href="#" onclick="window.open(\'editnews.php?user_id=' . Auth::id() . '\', \'_blank\', indx_window_specs); return false;">' . I18N::translate('Add a new journal entry') . '</a>';
     if ($template) {
         if ($block) {
             $class .= ' small_inner_block';
         }
         return Theme::theme()->formatBlock($id, $title, $class, $content);
     } else {
         return $content;
     }
 }
Example #11
0
 /**
  * Upgrade to to the next version
  */
 public function upgrade()
 {
     // Move repositories to their own table
     Database::exec("CREATE TABLE IF NOT EXISTS `##repository` (" . " repository_id INTEGER AUTO_INCREMENT                      NOT NULL," . " gedcom_id     INTEGER                                     NOT NULL," . " xref          VARCHAR(20)                                 NOT NULL," . " gedcom        LONGTEXT                                    NOT NULL," . " name          VARCHAR(90)                                 NOT NULL," . " address       VARCHAR(255)                                NOT NULL," . " restriction   ENUM('', 'confidential', 'privacy', 'none') NOT NULL," . " uid           VARCHAR(34)                                 NOT NULL," . " changed_at    DATETIME                                    NOT NULL," . " PRIMARY KEY (repository_id)," . " UNIQUE  KEY `##repository_ix1` (gedcom_id, xref)," . " UNIQUE  KEY `##repository_ix2` (xref, gedcom_id)," . "         KEY `##repository_ix3` (name)," . "         KEY `##repository_ix4` (address)," . "         KEY `##repository_ix5` (restriction)," . "         KEY `##repository_ix6` (uid)," . "         KEY `##repository_ix7` (changed_at)," . " CONSTRAINT `##repository_fk1` FOREIGN KEY (gedcom_id) REFERENCES `##gedcom` (gedcom_id)" . ") COLLATE utf8_unicode_ci ENGINE=InnoDB");
     Database::exec("START TRANSACTION");
     $repositories = Database::prepare("SELECT * FROM `##other` WHERE o_type = 'REPO'")->fetchAll();
     foreach ($repositories as $n => $repository) {
         Database::prepare("INSERT INTO `##repository` (" . " gedcom_id, xref, gedcom, name, address, restriction, uid, changed_at" . ") VALUES (" . " :gedcom_id, :xref, :gedcom, :name, :address, :restriction, :uid, :changed_at" . ")")->execute(array('gedcom_id' => $repository->o_file, 'xref' => $repository->o_id, 'gedcom' => $repository->o_gedcom, 'name' => '', 'address' => '', 'restriction' => '', 'uid' => '', 'changed_at' => ''));
         Database::prepare("DELETE FROM `##other` WHERE o_file = :gedcom_id AND o_id = :xref")->execute(array('gedcom_id' => $repository->o_file, 'xref' => $repository->o_id));
         if ($n % 500 === 499) {
             Database::exec("COMMIT");
             Database::exec("START TRANSACTION");
         }
     }
     Database::exec("COMMIT");
 }
Example #12
0
 /** {@inheritDoc} */
 public function upgrade()
 {
     $module_options = 'FTV_OPTIONS';
     $ftv_options = Database::prepare("SELECT setting_value FROM `##module_setting` WHERE setting_name=?")->execute(array($module_options))->fetchOne();
     $options = unserialize($ftv_options);
     if (!empty($options)) {
         foreach ($options as $option) {
             $option['SHOW_PDF_ICON'] = '2';
             $new_options[] = $option;
         }
         if (isset($new_options)) {
             Database::prepare("UPDATE `##module_setting` SET setting_value=? WHERE setting_name=?")->execute(array(serialize($new_options), $module_options));
         }
         unset($new_options);
     }
 }
Example #13
0
 /**
  * Upgrade to to the next version
  */
 public function upgrade()
 {
     // - changes to the values for the gedcom setting SHOW_RELATIVES_EVENTS
     $settings = Database::prepare("SELECT gedcom_id, setting_value FROM `##gedcom_setting` WHERE setting_name='SHOW_RELATIVES_EVENTS'")->fetchAssoc();
     foreach ($settings as $gedcom_id => $setting) {
         // Delete old settings
         $setting = preg_replace('/_(BIRT|MARR|DEAT)_(COUS|MSIB|FSIB|GGCH|NEPH|GGPA)/', '', $setting);
         $setting = preg_replace('/_FAMC_(RESI_EMIG)/', '', $setting);
         // Rename settings
         $setting = preg_replace('/_MARR_(MOTH|FATH|FAMC)/', '_MARR_PARE', $setting);
         $setting = preg_replace('/_DEAT_(MOTH|FATH)/', '_DEAT_PARE', $setting);
         // Remove duplicates
         preg_match_all('/[_A-Z]+/', $setting, $match);
         // And save
         Tree::findById($gedcom_id)->setPreference('SHOW_RELATIVES_EVENTS', implode(',', array_unique($match[0])));
     }
 }
 /**
  * Calculate the shortest paths - or all paths - between two individuals.
  *
  * @param Individual $individual1
  * @param Individual $individual2
  * @param bool       $all
  *
  * @return string[][]
  */
 public function calculateRelationships(Individual $individual1, Individual $individual2, $all)
 {
     $rows = Database::prepare("SELECT l_from, l_to FROM `##link` WHERE l_file = :tree_id AND l_type IN ('FAMS', 'FAMC', 'CHIL', 'HUSB', 'WIFE')")->execute(array('tree_id' => $individual1->getTree()->getTreeId()))->fetchAll();
     $graph = array();
     foreach ($rows as $row) {
         $graph[$row->l_from][$row->l_to] = 1;
     }
     $xref1 = $individual1->getXref();
     $xref2 = $individual2->getXref();
     $dijkstra = new Dijkstra($graph);
     $paths = $dijkstra->shortestPaths($xref1, $xref2);
     if ($all) {
         // Only process each exclusion list once;
         $excluded = array();
         $queue = array();
         foreach ($paths as $path) {
             // Insert the paths into the queue, with an exclusion list.
             $queue[] = array('path' => $path, 'exclude' => array());
             // While there are un-extended paths
             while (list(, $next) = each($queue)) {
                 // For each family on the path
                 for ($n = count($next['path']) - 2; $n >= 1; $n -= 2) {
                     $exclude = $next['exclude'];
                     $exclude[] = $next['path'][$n];
                     sort($exclude);
                     $tmp = implode('-', $exclude);
                     if (in_array($tmp, $excluded)) {
                         continue;
                     } else {
                         $excluded[] = $tmp;
                     }
                     // Add any new path to the queue
                     foreach ($dijkstra->shortestPaths($xref1, $xref2, $exclude) as $new_path) {
                         $queue[] = array('path' => $new_path, 'exclude' => $exclude);
                     }
                 }
             }
         }
         // Extract the paths from the queue, removing duplicates.
         $paths = array();
         foreach ($queue as $next) {
             $paths[implode('-', $next['path'])] = $next['path'];
         }
     }
     return $paths;
 }
Example #15
0
 /** {@inheritDoc} */
 public function upgrade()
 {
     // remove key 'LINK' from FTV_SETTINGS
     $module_settings = 'FTV_SETTINGS';
     $ftv_asettings = Database::prepare("SELECT setting_value FROM `##module_setting` WHERE setting_name=?")->execute(array($module_settings))->fetchOne();
     $asettings = unserialize($ftv_asettings);
     if (!empty($asettings)) {
         foreach ($asettings as $asetting) {
             if (array_key_exists('LINK', $asetting)) {
                 unset($asetting['LINK']);
                 $new_asettings[] = $asetting;
             }
         }
         if (isset($new_asettings)) {
             Database::prepare("UPDATE `##module_setting` SET setting_value=? WHERE setting_name=?")->execute(array(serialize($new_asettings), $module_settings));
         }
         unset($new_asettings);
     }
     $ftv_bsettings = Database::prepare("SELECT setting_value FROM `##module_setting` WHERE setting_name=?")->execute(array($module_settings))->fetchOne();
     $bsettings = unserialize($ftv_bsettings);
     if (!empty($bsettings)) {
         foreach ($bsettings as $bsetting) {
             if (!array_key_exists('DISPLAY_NAME', $bsetting)) {
                 $bsetting['DISPLAY_NAME'] = $bsetting['SURNAME'];
                 $new_bsettings[] = $bsetting;
             }
         }
         if (isset($new_bsettings)) {
             Database::prepare("UPDATE `##module_setting` SET setting_value=? WHERE setting_name=?")->execute(array(serialize($new_bsettings), $module_settings));
         }
         unset($new_bsettings);
     }
     $module_options = 'FTV_OPTIONS';
     $ftv_options = Database::prepare("SELECT setting_value FROM `##module_setting` WHERE setting_name=?")->execute(array($module_options))->fetchOne();
     $options = unserialize($ftv_options);
     if (!empty($options)) {
         foreach ($options as $option) {
             $option['USE_FULLNAME'] = '0';
             $new_options[] = $option;
         }
         if (isset($new_options)) {
             Database::prepare("UPDATE `##module_setting` SET setting_value=? WHERE setting_name=?")->execute(array(serialize($new_options), $module_options));
         }
         unset($new_options);
     }
 }
 /**
  * Manage updates sent from the AdminConfig@index form.
  */
 protected function update()
 {
     if (Auth::isAdmin()) {
         $ihooks = HookProvider::getInstance()->getInstalledHooks();
         $module_names = Database::prepare("SELECT module_name FROM `##module` WHERE status='disabled'")->fetchOneColumn();
         if ($ihooks !== null) {
             foreach ($ihooks as $ihook => $params) {
                 if (Filter::post('hook-' . $params['id']) === 'yes') {
                     $array_hook = explode('#', $ihook);
                     //Update status
                     $new_status = Filter::postBool('status-' . $params['id']);
                     if (in_array($array_hook[0], $module_names)) {
                         $new_status = false;
                     }
                     $previous_status = $params['status'];
                     if ($new_status !== null) {
                         $new_status = $new_status ? 'enabled' : 'disabled';
                         if ($new_status != $previous_status) {
                             $chook = new Hook($array_hook[1], $array_hook[2]);
                             switch ($new_status) {
                                 case 'enabled':
                                     $chook->enable($array_hook[0]);
                                     break;
                                 case 'disabled':
                                     $chook->disable($array_hook[0]);
                                     break;
                                 default:
                                     break;
                             }
                         }
                     }
                     //Update priority
                     $new_priority = Filter::postInteger("moduleorder-{$params['id']}");
                     $previous_priority = $params['priority'];
                     if ($new_priority !== null) {
                         if ($new_priority != $previous_priority) {
                             $chook = new Hook($array_hook[1], $array_hook[2]);
                             $chook->setPriority($array_hook[0], $new_priority);
                         }
                     }
                 }
             }
         }
     }
 }
Example #17
0
 /** {@inheritDoc} */
 public function upgrade()
 {
     // Add new options 'NUMBLOCKS' and 'CHECK_RELATIONSHIP'
     $module_options = 'FTV_OPTIONS';
     $ftv_options = Database::prepare("SELECT setting_value FROM `##module_setting` WHERE setting_name=?")->execute(array($module_options))->fetchOne();
     $options = unserialize($ftv_options);
     if (!empty($options)) {
         foreach ($options as $option) {
             $option['NUMBLOCKS'] = '0';
             $option['CHECK_RELATIONSHIP'] = '0';
             $new_options[] = $option;
         }
         if (isset($new_options)) {
             Database::prepare("UPDATE `##module_setting` SET setting_value=? WHERE setting_name=?")->execute(array(serialize($new_options), $module_options));
         }
         unset($new_options);
     }
 }
Example #18
0
 /** {@inheritDoc} */
 public function upgrade()
 {
     // Add options 'THUMB_SIZE', 'USE_SQUARE_THUMBS and 'SHOW_USERFORM'
     $module_options = 'FTV_OPTIONS';
     $ftv_options = Database::prepare("SELECT setting_value FROM `##module_setting` WHERE setting_name=?")->execute(array($module_options))->fetchOne();
     $options = unserialize($ftv_options);
     if (!empty($options)) {
         foreach ($options as $option) {
             $option['THUMB_SIZE'] = '60';
             $option['USE_SQUARE_THUMBS'] = '1';
             $option['SHOW_USERFORM'] = '2';
             $new_options[] = $option;
         }
         if (isset($new_options)) {
             Database::prepare("UPDATE `##module_setting` SET setting_value=? WHERE setting_name=?")->execute(array(serialize($new_options), $module_options));
         }
         unset($new_options);
     }
 }
Example #19
0
 /**
  * Check with the webtrees.net server for the latest version of webtrees.
  * Fetching the remote file can be slow, so check infrequently, and cache the result.
  * Pass the current versions of webtrees, PHP and MySQL, as the response
  * may be different for each.  The server logs are used to generate
  * installation statistics which can be found at http://svn.webtrees.net/statistics.html
  *
  * @return null|string
  */
 public static function fetchLatestVersion()
 {
     $last_update_timestamp = Site::getPreference('LATEST_WT_VERSION_TIMESTAMP');
     if ($last_update_timestamp < WT_TIMESTAMP - 24 * 60 * 60) {
         $row = Database::prepare("SHOW VARIABLES LIKE 'version'")->fetchOneRow();
         $params = '?w=' . WT_VERSION . '&p=' . PHP_VERSION . '&m=' . $row->value . '&o=' . (DIRECTORY_SEPARATOR === '/' ? 'u' : 'w');
         $latest_version_txt = File::fetchUrl('http://dev.webtrees.net/build/latest-version.txt' . $params);
         if ($latest_version_txt) {
             Site::setPreference('LATEST_WT_VERSION', $latest_version_txt);
             Site::setPreference('LATEST_WT_VERSION_TIMESTAMP', WT_TIMESTAMP);
             return $latest_version_txt;
         } else {
             // Cannot connect to server - use cached version (if we have one)
             return Site::getPreference('LATEST_WT_VERSION');
         }
     } else {
         return Site::getPreference('LATEST_WT_VERSION');
     }
 }
Example #20
0
 public function modAction($mod_action)
 {
     switch ($mod_action) {
         case 'admin_config':
             if (Filter::postBool('save')) {
                 $this->setSetting('FRL_PLUGINS', serialize(Filter::post('NEW_FRL_PLUGINS')));
                 Log::addConfigurationLog($this->getTitle() . ' config updated');
             }
             $template = new AdminTemplate();
             return $template->pageContent();
         case 'admin_reset':
             Database::prepare("DELETE FROM `##module_setting` WHERE setting_name LIKE 'FRL%'")->execute();
             Log::addConfigurationLog($this->getTitle() . ' reset to default values');
             header('Location: ' . $this->getConfigLink());
             break;
         default:
             http_response_code(404);
             break;
     }
 }
Example #21
0
 /**
  * Generate the HTML content of this block.
  *
  * @param int      $block_id
  * @param bool     $template
  * @param string[] $cfg
  *
  * @return string
  */
 public function getBlock($block_id, $template = true, $cfg = array())
 {
     global $ctype, $WT_TREE;
     switch (Filter::get('action')) {
         case 'deletenews':
             $news_id = Filter::getInteger('news_id');
             if ($news_id) {
                 Database::prepare("DELETE FROM `##news` WHERE news_id = ?")->execute(array($news_id));
             }
             break;
     }
     $articles = Database::prepare("SELECT SQL_CACHE news_id, user_id, gedcom_id, UNIX_TIMESTAMP(updated) + :offset AS updated, subject, body FROM `##news` WHERE user_id = :user_id ORDER BY updated DESC")->execute(array('offset' => WT_TIMESTAMP_OFFSET, 'user_id' => Auth::id()))->fetchAll();
     $id = $this->getName() . $block_id;
     $class = $this->getName() . '_block';
     $title = $this->getTitle();
     $content = '';
     if (empty($articles)) {
         $content .= '<p>' . I18N::translate('You have not created any journal items.') . '</p>';
     }
     foreach ($articles as $article) {
         $content .= '<div class="journal_box">';
         $content .= '<div class="news_title">' . Filter::escapeHtml($article->subject) . '</div>';
         $content .= '<div class="news_date">' . FunctionsDate::formatTimestamp($article->updated) . '</div>';
         if ($article->body == strip_tags($article->body)) {
             $article->body = nl2br($article->body, false);
         }
         $content .= $article->body;
         $content .= '<a href="#" onclick="window.open(\'editnews.php?news_id=\'+' . $article->news_id . ', \'_blank\', indx_window_specs); return false;">' . I18N::translate('Edit') . '</a>';
         $content .= ' | ';
         $content .= '<a href="index.php?action=deletenews&amp;news_id=' . $article->news_id . '&amp;ctype=' . $ctype . '&amp;ged=' . $WT_TREE->getNameHtml() . '" onclick="return confirm(\'' . I18N::translate('Are you sure you want to delete “%s”?', Filter::escapeHtml($article->subject)) . "');\">" . I18N::translate('Delete') . '</a><br>';
         $content .= '</div><br>';
     }
     $content .= '<p><a href="#" onclick="window.open(\'editnews.php?user_id=' . Auth::id() . '\', \'_blank\', indx_window_specs); return false;">' . I18N::translate('Add a journal entry') . '</a></p>';
     if ($template) {
         return Theme::theme()->formatBlock($id, $title, $class, $content);
     } else {
         return $content;
     }
 }
Example #22
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 Tree   $tree   only fetch individuals from this tree
  * @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
  *
  * @return Individual[]
  */
 public static function individuals(Tree $tree, $surn, $salpha, $galpha, $marnm, $fams)
 {
     $sql = "SELECT i_id AS xref, 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 = :tree_id " . ($marnm ? "" : "AND n_type != '_MARNM'");
     $args = array('tree_id' => $tree->getTreeId());
     if ($surn) {
         $sql .= " AND n_surn COLLATE :collate_1 = :surn";
         $args['collate_1'] = I18N::collation();
         $args['surn'] = $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 :collate_2, CASE n_givn WHEN '@P.N.' THEN 1 ELSE 0 END, n_givn COLLATE :collate_3";
     $args['collate_2'] = I18N::collation();
     $args['collate_3'] = I18N::collation();
     $list = array();
     $rows = Database::prepare($sql)->execute($args)->fetchAll();
     foreach ($rows as $row) {
         $person = Individual::getInstance($row->xref, $tree, $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;
 }
Example #23
0
if ($dbname_ok) {
    try {
        // PhpGedView (4.2.3 and earlier) and many other applications have a USERS table.
        // webtrees has a USER table
        Database::prepare("SELECT COUNT(*) FROM `##users`")->fetchOne();
        echo '<p class="bad">', I18N::translate('This database and table-prefix appear to be used by another application.  If you have an existing PhpGedView system, you should create a new webtrees system.  You can import your PhpGedView data and settings later.'), '</p>';
        $dbname_ok = false;
    } catch (PDOException $ex) {
        // Table not found?  Good!
    }
}
if ($dbname_ok) {
    try {
        // PhpGedView (4.2.4 and later) has a site_setting.site_setting_name column.
        // [We changed the column name in webtrees, so we can tell the difference!]
        Database::prepare("SELECT site_setting_value FROM `##site_setting` WHERE site_setting_name='PGV_SCHEMA_VERSION'")->fetchOne();
        echo '<p class="bad">', I18N::translate('This database and table-prefix appear to be used by another application.  If you have an existing PhpGedView system, you should create a new webtrees system.  You can import your PhpGedView data and settings later.'), '</p>';
        $dbname_ok = false;
    } catch (PDOException $ex) {
        // Table/column not found?  Good!
    }
}
if (!$dbname_ok) {
    echo '<h2>', I18N::translate('Database and table names'), '</h2>', '<p>', I18N::translate('A database server can store many separate databases.  You need to select an existing database (created by your server’s administrator) or create a new one (if your database user account has sufficient privileges).'), '</p>', '<fieldset><legend>', I18N::translate('Database name'), '</legend>', '<table border="0"><tr><td>', I18N::translate('Database name'), '</td><td>', '<input type="text" name="dbname" value="', Filter::escapeHtml($_POST['dbname']), '" autofocus></td><td>', I18N::translate('This is case sensitive.  If a database with this name does not already exist webtrees will attempt to create one for you.  Success will depend on permissions set for your web server, but you will be notified if this fails.'), '</td></tr><tr><td>', I18N::translate('Table prefix'), '</td><td>', '<input type="text" name="tblpfx" value="', Filter::escapeHtml($_POST['tblpfx']), '"></td><td>', I18N::translate('The prefix is optional, but recommended.  By giving the table names a unique prefix you can let several different applications share the same database.  “wt_” is suggested, but can be anything you want.'), '</td></tr></table>', '</fieldset>', '<br><hr><input type="submit" id="btncontinue" value="', I18N::translate('continue'), '">', '</form>', '</body></html>';
    return;
} else {
    // Copy these values through to the next step
    echo '<input type="hidden" name="dbname" value="', Filter::escapeHtml($_POST['dbname']), '">';
    echo '<input type="hidden" name="tblpfx" value="', Filter::escapeHtml($_POST['tblpfx']), '">';
}
////////////////////////////////////////////////////////////////////////////////
Example #24
0
 private function getMenuList()
 {
     global $WT_TREE;
     return webtrees\Database::prepare("SELECT block_id, bs1.setting_value AS menu_title, bs2.setting_value AS menu_access, bs3.setting_value AS menu_address" . " FROM `##block` b" . " JOIN `##block_setting` bs1 USING (block_id)" . " JOIN `##block_setting` bs2 USING (block_id)" . " JOIN `##block_setting` bs3 USING (block_id)" . " WHERE module_name=?" . " AND bs1.setting_name='menu_title'" . " AND bs2.setting_name='menu_access'" . " AND bs3.setting_name='menu_address'" . " AND (gedcom_id IS NULL OR gedcom_id=?)" . " ORDER BY block_order")->execute(array($this->getName(), $WT_TREE->getTreeId()))->fetchAll();
 }
 /**
  * Search for individuals in a tree.
  *
  * @param Tree   $tree  Search this tree
  * @param string $query Search for this text
  *
  * @return string
  */
 private function search(Tree $tree, $query)
 {
     if (strlen($query) < 2) {
         return '';
     }
     $rows = Database::prepare("SELECT i_id AS xref, i_gedcom AS gedcom" . " FROM `##individuals`, `##name`" . " WHERE (i_id LIKE CONCAT('%', :query_1, '%') OR n_sort LIKE CONCAT('%', :query_2, '%'))" . " AND i_id = n_id AND i_file = n_file AND i_file = :tree_id" . " ORDER BY n_sort COLLATE :collation" . " LIMIT 50")->execute(array('query_1' => $query, 'query_2' => $query, 'tree_id' => $tree->getTreeId(), 'collation' => I18N::collation()))->fetchAll();
     $out = '<ul>';
     foreach ($rows as $row) {
         $person = Individual::getInstance($row->xref, $tree, $row->gedcom);
         if ($person->canShowName()) {
             $out .= '<li><a href="' . $person->getHtmlUrl() . '">' . $person->getSexImage() . ' ' . $person->getFullName() . ' ';
             if ($person->canShow()) {
                 $bd = $person->getLifeSpan();
                 if (!empty($bd)) {
                     $out .= ' (' . $bd . ')';
                 }
             }
             $out .= '</a></li>';
         }
     }
     $out .= '</ul>';
     return $out;
 }
Example #26
0
         // $datum[6] is the sortable registration timestamp
         $datum[7] = $datum[7] ? FunctionsDate::formatTimestamp($datum[7]) : '';
         if (date("U") - $datum[6] > 604800 && !$datum[10]) {
             $datum[7] = '<span class="red">' . $datum[7] . '</span>';
         }
         // $datum[8] is the sortable last-login timestamp
         if ($datum[8]) {
             $datum[9] = FunctionsDate::formatTimestamp($datum[8]) . '<br>' . I18N::timeAgo(WT_TIMESTAMP - $datum[8]);
         } else {
             $datum[9] = I18N::translate('Never');
         }
         $datum[10] = $datum[10] ? I18N::translate('yes') : I18N::translate('no');
         $datum[11] = $datum[11] ? I18N::translate('yes') : I18N::translate('no');
     }
     // Total filtered/unfiltered rows
     $recordsFiltered = (int) Database::prepare("SELECT FOUND_ROWS()")->fetchOne();
     $recordsTotal = User::count();
     header('Content-type: application/json');
     // See http://www.datatables.net/usage/server-side
     echo json_encode(array('draw' => Filter::getInteger('draw'), 'recordsTotal' => $recordsTotal, 'recordsFiltered' => $recordsFiltered, 'data' => $data));
     return;
 case 'edit':
     $user_id = Filter::getInteger('user_id');
     if ($user_id === 0) {
         $controller->setPageTitle(I18N::translate('Add a user'));
         $tmp = new \stdClass();
         $tmp->user_id = '';
         $tmp->user_name = '';
         $tmp->real_name = '';
         $tmp->email = '';
         $user = new User($tmp);
Example #27
0
 /**
  * How many news items exist for this tree.
  *
  * @return string
  */
 public function totalGedcomNews()
 {
     try {
         $number = (int) Database::prepare("SELECT SQL_CACHE COUNT(*) FROM `##news` WHERE gedcom_id = ?")->execute(array($this->tree->getTreeId()))->fetchOne();
     } catch (PDOException $ex) {
         // The module may not be installed, so the table may not exist.
         $number = 0;
     }
     return I18N::number($number);
 }
Example #28
0
 /**
  * Export the database in GEDCOM format
  *
  * @param Tree $tree Which tree to export
  * @param resource $gedout Handle to a writable stream
  * @param string[] $exportOptions Export options are as follows:
  *                                'privatize':    which Privacy rules apply? (none, visitor, user, manager)
  *                                'toANSI':       should the output be produced in ISO-8859-1 instead of UTF-8? (yes, no)
  *                                'path':         what constant should prefix all media file paths? (eg: media/  or c:\my pictures\my family
  *                                'slashes':      what folder separators apply to media file paths? (forward, backward)
  */
 public static function exportGedcom(Tree $tree, $gedout, $exportOptions)
 {
     switch ($exportOptions['privatize']) {
         case 'gedadmin':
             $access_level = Auth::PRIV_NONE;
             break;
         case 'user':
             $access_level = Auth::PRIV_USER;
             break;
         case 'visitor':
             $access_level = Auth::PRIV_PRIVATE;
             break;
         case 'none':
             $access_level = Auth::PRIV_HIDE;
             break;
     }
     $head = self::gedcomHeader($tree);
     if ($exportOptions['toANSI'] == 'yes') {
         $head = str_replace('UTF-8', 'ANSI', $head);
         $head = utf8_decode($head);
     }
     $head = self::reformatRecord($head);
     fwrite($gedout, $head);
     // Buffer the output. Lots of small fwrite() calls can be very slow when writing large gedcoms.
     $buffer = '';
     // Generate the OBJE/SOUR/REPO/NOTE records first, as their privacy calcualations involve
     // database queries, and we wish to avoid large gaps between queries due to MySQL connection timeouts.
     $tmp_gedcom = '';
     $rows = Database::prepare("SELECT m_id AS xref, m_gedcom AS gedcom" . " FROM `##media` WHERE m_file = :tree_id ORDER BY m_id")->execute(array('tree_id' => $tree->getTreeId()))->fetchAll();
     foreach ($rows as $row) {
         $rec = Media::getInstance($row->xref, $tree, $row->gedcom)->privatizeGedcom($access_level);
         $rec = self::convertMediaPath($rec, $exportOptions['path']);
         if ($exportOptions['toANSI'] === 'yes') {
             $rec = utf8_decode($rec);
         }
         $tmp_gedcom .= self::reformatRecord($rec);
     }
     $rows = Database::prepare("SELECT s_id AS xref, s_file AS gedcom_id, s_gedcom AS gedcom" . " FROM `##sources` WHERE s_file = :tree_id ORDER BY s_id")->execute(array('tree_id' => $tree->getTreeId()))->fetchAll();
     foreach ($rows as $row) {
         $rec = Source::getInstance($row->xref, $tree, $row->gedcom)->privatizeGedcom($access_level);
         if ($exportOptions['toANSI'] === 'yes') {
             $rec = utf8_decode($rec);
         }
         $tmp_gedcom .= self::reformatRecord($rec);
     }
     $rows = Database::prepare("SELECT o_type AS type, o_id AS xref, o_gedcom AS gedcom" . " FROM `##other` WHERE o_file = :tree_id AND o_type NOT IN ('HEAD', 'TRLR') ORDER BY o_id")->execute(array('tree_id' => $tree->getTreeId()))->fetchAll();
     foreach ($rows as $row) {
         switch ($row->type) {
             case 'NOTE':
                 $record = Note::getInstance($row->xref, $tree, $row->gedcom);
                 break;
             case 'REPO':
                 $record = Repository::getInstance($row->xref, $tree, $row->gedcom);
                 break;
             default:
                 $record = GedcomRecord::getInstance($row->xref, $tree, $row->gedcom);
                 break;
         }
         $rec = $record->privatizeGedcom($access_level);
         if ($exportOptions['toANSI'] === 'yes') {
             $rec = utf8_decode($rec);
         }
         $tmp_gedcom .= self::reformatRecord($rec);
     }
     $rows = Database::prepare("SELECT i_id AS xref, i_gedcom AS gedcom" . " FROM `##individuals` WHERE i_file = :tree_id ORDER BY i_id")->execute(array('tree_id' => $tree->getTreeId()))->fetchAll();
     foreach ($rows as $row) {
         $rec = Individual::getInstance($row->xref, $tree, $row->gedcom)->privatizeGedcom($access_level);
         if ($exportOptions['toANSI'] === 'yes') {
             $rec = utf8_decode($rec);
         }
         $buffer .= self::reformatRecord($rec);
         if (strlen($buffer) > 65536) {
             fwrite($gedout, $buffer);
             $buffer = '';
         }
     }
     $rows = Database::prepare("SELECT f_id AS xref, f_gedcom AS gedcom" . " FROM `##families` WHERE f_file = :tree_id ORDER BY f_id")->execute(array('tree_id' => $tree->getTreeId()))->fetchAll();
     foreach ($rows as $row) {
         $rec = Family::getInstance($row->xref, $tree, $row->gedcom)->privatizeGedcom($access_level);
         if ($exportOptions['toANSI'] === 'yes') {
             $rec = utf8_decode($rec);
         }
         $buffer .= self::reformatRecord($rec);
         if (strlen($buffer) > 65536) {
             fwrite($gedout, $buffer);
             $buffer = '';
         }
     }
     fwrite($gedout, $buffer);
     fwrite($gedout, $tmp_gedcom);
     fwrite($gedout, '0 TRLR' . WT_EOL);
 }
Example #29
0
                return;
        }
        $first_time = false;
        // Re-fetch the data, now that we have performed character set conversion.
        $data = Database::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) {
            FunctionsImport::importRecord($rec, $tree, false);
        }
        // Mark the chunk as imported
        Database::prepare("UPDATE `##gedcom_chunk` SET imported=TRUE WHERE gedcom_chunk_id=?")->execute(array($data->gedcom_chunk_id));
    } catch (PDOException $ex) {
        Database::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.....
            $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 . '").removeClass("hidden");');
        }
        return;
    }
}
Database::commit();
Example #30
0
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
namespace Fisharebest\Webtrees;

/**
 * Defined in session.php
 *
 * @global Tree $WT_TREE
 */
global $WT_TREE;
use Fisharebest\Webtrees\Controller\PageController;
use Fisharebest\Webtrees\Module\CkeditorModule;
define('WT_SCRIPT_NAME', 'block_edit.php');
require './includes/session.php';
$block_id = Filter::getInteger('block_id');
$block = Database::prepare("SELECT SQL_CACHE * FROM `##block` WHERE block_id=?")->execute(array($block_id))->fetchOneRow();
// Check access.  (1) the block must exist and be enabled, (2) gedcom blocks require
// managers, (3) user blocks require the user or an admin
$blocks = Module::getActiveBlocks($WT_TREE);
if (!$block || !array_key_exists($block->module_name, $blocks) || $block->gedcom_id && !Auth::isManager(Tree::findById($block->gedcom_id)) || $block->user_id && $block->user_id != Auth::id() && !Auth::isAdmin()) {
    header('Location: ' . WT_BASE_URL);
    return;
}
$block = $blocks[$block->module_name];
if (Filter::post('save')) {
    $ctype = Filter::post('ctype', 'user', 'gedcom');
    header('Location: ' . WT_BASE_URL . 'index.php?ctype=' . $ctype . '&ged=' . $WT_TREE->getNameUrl());
    $block->configureBlock($block_id);
    return;
}
$ctype = FIlter::get('ctype', 'user', 'gedcom');