Example #1
0
    private function edit()
    {
        global $WT_TREE;
        if (webtrees\Filter::postBool('save') && webtrees\Filter::checkCsrf()) {
            $block_id = webtrees\Filter::post('block_id');
            if ($block_id) {
                webtrees\Database::prepare("UPDATE `##block` SET gedcom_id=NULLIF(?, ''), block_order=? WHERE block_id=?")->execute(array(webtrees\Filter::post('gedcom_id'), (int) webtrees\Filter::post('block_order'), $block_id));
            } else {
                webtrees\Database::prepare("INSERT INTO `##block` (gedcom_id, module_name, block_order) VALUES (NULLIF(?, ''), ?, ?)")->execute(array(webtrees\Filter::post('gedcom_id'), $this->getName(), (int) webtrees\Filter::post('block_order')));
                $block_id = webtrees\Database::getInstance()->lastInsertId();
            }
            $this->setBlockSetting($block_id, 'menu_title', webtrees\Filter::post('menu_title'));
            $this->setBlockSetting($block_id, 'menu_address', webtrees\Filter::post('menu_address'));
            $this->setBlockSetting($block_id, 'menu_access', webtrees\Filter::post('menu_access'));
            $languages = array();
            foreach (webtrees\I18N::installedLocales() as $locale) {
                if (webtrees\Filter::postBool('lang_' . $locale->languageTag())) {
                    $languages[] = $locale->languageTag();
                }
            }
            $this->setBlockSetting($block_id, 'languages', implode(',', $languages));
            $this->config();
        } else {
            $block_id = webtrees\Filter::get('block_id');
            $controller = new webtrees\Controller\PageController();
            $controller->restrictAccess(webtrees\Auth::isEditor($WT_TREE));
            if ($block_id) {
                $controller->setPageTitle(webtrees\I18N::translate('Edit menu'));
                $menu_title = $this->getBlockSetting($block_id, 'menu_title');
                $menu_address = $this->getBlockSetting($block_id, 'menu_address');
                $menu_access = $this->getBlockSetting($block_id, 'menu_access');
                $block_order = webtrees\Database::prepare("SELECT block_order FROM `##block` WHERE block_id=?")->execute(array($block_id))->fetchOne();
                $gedcom_id = webtrees\Database::prepare("SELECT gedcom_id FROM `##block` WHERE block_id=?")->execute(array($block_id))->fetchOne();
            } else {
                $controller->setPageTitle(webtrees\I18N::translate('Add menu'));
                $menu_access = 1;
                $menu_title = '';
                $menu_address = '';
                $block_order = webtrees\Database::prepare("SELECT IFNULL(MAX(block_order)+1, 0) FROM `##block` WHERE module_name=?")->execute(array($this->getName()))->fetchOne();
                $gedcom_id = $WT_TREE->getTreeId();
            }
            $controller->pageHeader();
            ?>
			
			<ol class="breadcrumb small">
				<li><a href="admin.php"><?php 
            echo webtrees\I18N::translate('Control panel');
            ?>
</a></li>
				<li><a href="admin_modules.php"><?php 
            echo webtrees\I18N::translate('Module administration');
            ?>
</a></li>
				<li><a href="module.php?mod=<?php 
            echo $this->getName();
            ?>
&mod_action=admin_config"><?php 
            echo webtrees\I18N::translate($this->getTitle());
            ?>
</a></li>
				<li class="active"><?php 
            echo $controller->getPageTitle();
            ?>
</li>
			</ol>
			
			<form class="form-horizontal" method="POST" action="#" name="menu" id="menuForm">
				<?php 
            echo webtrees\Filter::getCsrf();
            ?>
				<input type="hidden" name="save" value="1">
				<input type="hidden" name="block_id" value="<?php 
            echo $block_id;
            ?>
">
				<h3><?php 
            echo webtrees\I18N::translate('General');
            ?>
</h3>
				
				<div class="form-group">
					<label class="control-label col-sm-3" for="menu_title">
						<?php 
            echo webtrees\I18N::translate('Title');
            ?>
					</label>
					<div class="col-sm-9">
						<input
							class="form-control"
							id="menu_title"
							size="90"
							name="menu_title"
							required
							type="text"
							value="<?php 
            echo webtrees\Filter::escapeHtml($menu_title);
            ?>
"
							>
					</div>
					<span class="help-block col-sm-9 col-sm-offset-3 small text-muted">
						<?php 
            echo webtrees\I18N::translate('Add your menu title here');
            ?>
					</span>
				</div>
				<div class="form-group">
					<label class="control-label col-sm-3" for="menu_address">
						<?php 
            echo webtrees\I18N::translate('Menu address');
            ?>
					</label>
					<div class="col-sm-9">
						<input
							class="form-control"
							id="menu_address"
							size="90"
							name="menu_address"
							required
							type="text"
							value="<?php 
            echo webtrees\Filter::escapeHtml($menu_address);
            ?>
"
							>
					</div>
					<span class="help-block col-sm-9 col-sm-offset-3 small text-muted">
						<?php 
            echo webtrees\I18N::translate('Add your menu address here');
            ?>
					</span>
				</div>
				
				<h3><?php 
            echo webtrees\I18N::translate('Languages');
            ?>
</h3>
				
				<div class="form-group">
					<label class="control-label col-sm-3" for="lang_*">
						<?php 
            echo webtrees\I18N::translate('Show this menu for which languages?');
            ?>
					</label>
					<div class="col-sm-9">
						<?php 
            $accepted_languages = explode(',', $this->getBlockSetting($block_id, 'languages'));
            foreach (webtrees\I18N::installedLocales() as $locale) {
                ?>
								<div class="checkbox">
									<label title="<?php 
                echo $locale->languageTag();
                ?>
">
										<input type="checkbox" name="lang_<?php 
                echo $locale->languageTag();
                ?>
" <?php 
                echo in_array($locale->languageTag(), $accepted_languages) ? 'checked' : '';
                ?>
 ><?php 
                echo $locale->endonym();
                ?>
									</label>
								</div>
						<?php 
            }
            ?>
					</div>
				</div>
				
				<h3><?php 
            echo webtrees\I18N::translate('Visibility and Access');
            ?>
</h3>
				
				<div class="form-group">
					<label class="control-label col-sm-3" for="block_order">
						<?php 
            echo webtrees\I18N::translate('Menu position');
            ?>
					</label>
					<div class="col-sm-9">
						<input
							class="form-control"
							id="position"
							name="block_order"
							size="3"
							required
							type="number"
							value="<?php 
            echo webtrees\Filter::escapeHtml($block_order);
            ?>
"
						>
					</div>
					<span class="help-block col-sm-9 col-sm-offset-3 small text-muted">
						<?php 
            echo webtrees\I18N::translate('This field controls the order in which the menu items are displayed.'), '<br><br>', webtrees\I18N::translate('You do not have to enter the numbers sequentially. If you leave holes in the numbering scheme, you can insert other menu items later. For example, if you use the numbers 1, 6, 11, 16, you can later insert menu items with the missing sequence numbers. Negative numbers and zero are allowed, and can be used to insert menu items in front of the first one.'), '<br><br>', webtrees\I18N::translate('When more than one menu item has the same position number, only one of these menu items will be visible.');
            ?>
					</span>
				</div>
				<div class="form-group">
					<label class="control-label col-sm-3" for="block_order">
						<?php 
            echo webtrees\I18N::translate('Menu visibility');
            ?>
					</label>
					<div class="col-sm-9">
						<?php 
            echo webtrees\Functions\FunctionsEdit::selectEditControl('gedcom_id', webtrees\Tree::getIdList(), webtrees\I18N::translate('All'), $WT_TREE->getTreeId(), 'class="form-control"');
            ?>
					</div>
					<span class="help-block col-sm-9 col-sm-offset-3 small text-muted">
						<?php 
            echo webtrees\I18N::translate('You can determine whether this menu item will be visible regardless of family tree, or whether it will be visible only to the current family tree.');
            ?>
					</span>
				</div>
				<div class="form-group">
					<label class="control-label col-sm-3" for="menu_access">
						<?php 
            echo webtrees\I18N::translate('Access level');
            ?>
					</label>
					<div class="col-sm-9">
						<?php 
            echo webtrees\Functions\FunctionsEdit::editFieldAccessLevel('menu_access', $menu_access, 'class="form-control"');
            ?>
					</div>
				</div>
				
				<div class="row col-sm-9 col-sm-offset-3">
					<button class="btn btn-primary" type="submit">
						<i class="fa fa-check"></i>
						<?php 
            echo webtrees\I18N::translate('save');
            ?>
					</button>
					<button class="btn" type="button" onclick="window.location='<?php 
            echo $this->getConfigLink();
            ?>
';">
						<i class="fa fa-close"></i>
						<?php 
            echo webtrees\I18N::translate('cancel');
            ?>
					</button>
				</div>
			</form>
<?php 
        }
    }
    /**
     * Action from the configuration page
     */
    private function edit()
    {
        global $WT_TREE;
        if (Filter::postBool('save') && Filter::checkCsrf()) {
            $block_id = Filter::postInteger('block_id');
            if ($block_id) {
                Database::prepare("UPDATE `##block` SET gedcom_id = NULLIF(:tree_id, '0'), block_order = :block_order WHERE block_id = :block_id")->execute(array('tree_id' => Filter::postInteger('gedcom_id'), 'block_order' => Filter::postInteger('block_order'), 'block_id' => $block_id));
            } else {
                Database::prepare("INSERT INTO `##block` (gedcom_id, module_name, block_order) VALUES (NULLIF(:tree_id, '0'), :module_name, :block_order)")->execute(array('tree_id' => Filter::postInteger('gedcom_id'), 'module_name' => $this->getName(), 'block_order' => Filter::postInteger('block_order')));
                $block_id = Database::getInstance()->lastInsertId();
            }
            $this->setBlockSetting($block_id, 'header', Filter::post('header'));
            $this->setBlockSetting($block_id, 'faqbody', Filter::post('faqbody'));
            $languages = Filter::postArray('lang');
            $this->setBlockSetting($block_id, 'languages', implode(',', $languages));
            $this->config();
        } else {
            $block_id = Filter::getInteger('block_id');
            $controller = new PageController();
            if ($block_id) {
                $controller->setPageTitle(I18N::translate('Edit FAQ item'));
                $header = $this->getBlockSetting($block_id, 'header');
                $faqbody = $this->getBlockSetting($block_id, 'faqbody');
                $block_order = Database::prepare("SELECT block_order FROM `##block` WHERE block_id = :block_id")->execute(array('block_id' => $block_id))->fetchOne();
                $gedcom_id = Database::prepare("SELECT gedcom_id FROM `##block` WHERE block_id = :block_id")->execute(array('block_id' => $block_id))->fetchOne();
            } else {
                $controller->setPageTitle(I18N::translate('Add an FAQ item'));
                $header = '';
                $faqbody = '';
                $block_order = Database::prepare("SELECT IFNULL(MAX(block_order)+1, 0) FROM `##block` WHERE module_name = :module_name")->execute(array('module_name' => $this->getName()))->fetchOne();
                $gedcom_id = $WT_TREE->getTreeId();
            }
            $controller->pageHeader();
            if (Module::getModuleByName('ckeditor')) {
                CkeditorModule::enableEditor($controller);
            }
            ?>
			<ol class="breadcrumb small">
				<li><a href="admin.php"><?php 
            echo I18N::translate('Control panel');
            ?>
</a></li>
				<li><a href="admin_modules.php"><?php 
            echo I18N::translate('Module administration');
            ?>
</a></li>
				<li><a
						href="module.php?mod=<?php 
            echo $this->getName();
            ?>
&mod_action=admin_config"><?php 
            echo I18N::translate('Frequently asked questions');
            ?>
</a>
				</li>
				<li class="active"><?php 
            echo $controller->getPageTitle();
            ?>
</li>
			</ol>
			<h1><?php 
            echo $controller->getPageTitle();
            ?>
</h1>

			<form name="faq" class="form-horizontal" method="post" action="module.php?mod=<?php 
            echo $this->getName();
            ?>
&amp;mod_action=admin_edit">
			<?php 
            echo Filter::getCsrf();
            ?>
			<input type="hidden" name="save" value="1">
			<input type="hidden" name="block_id" value="<?php 
            echo $block_id;
            ?>
">

			<div class="form-group">
				<label for="header" class="col-sm-3 control-label">
					<?php 
            echo I18N::translate('Question');
            ?>
				</label>

				<div class="col-sm-9">
					<input type="text" class="form-control" name="header" id="header"
					       value="<?php 
            echo Filter::escapeHtml($header);
            ?>
">
				</div>
			</div>

			<div class="form-group">
				<label for="faqbody" class="col-sm-3 control-label">
					<?php 
            echo I18N::translate('Answer');
            ?>
				</label>

				<div class="col-sm-9">
					<textarea name="faqbody" id="faqbody" class="form-control html-edit"
					          rows="10"><?php 
            echo Filter::escapeHtml($faqbody);
            ?>
</textarea>
				</div>
			</div>

			<div class="form-group">
				<label for="xref" class="col-sm-3 control-label">
					<?php 
            echo I18N::translate('Show this block for which languages?');
            ?>
				</label>

				<div class="col-sm-9">
					<?php 
            echo FunctionsEdit::editLanguageCheckboxes('lang', explode(',', $this->getBlockSetting($block_id, 'languages')));
            ?>
				</div>
			</div>

			<div class="form-group">
				<label for="block_order" class="col-sm-3 control-label">
					<?php 
            echo I18N::translate('FAQ position');
            ?>
				</label>

				<div class="col-sm-9">
					<input type="text" name="block_order" id="block_order" class="form-control" value="<?php 
            echo $block_order;
            ?>
">
				</div>
			</div>

			<div class="form-group">
				<label for="gedcom_id" class="col-sm-3 control-label">
					<?php 
            echo I18N::translate('FAQ visibility');
            ?>
				</label>

				<div class="col-sm-9">
					<?php 
            echo FunctionsEdit::selectEditControl('gedcom_id', Tree::getIdList(), I18N::translate('All'), $gedcom_id, 'class="form-control"');
            ?>
					<p class="small text-muted">
						<?php 
            echo I18N::translate('A FAQ item can be displayed on just one of the family trees, or on all the family trees.');
            ?>
					</p>
				</div>
			</div>

			<div class="form-group">
				<div class="col-sm-offset-3 col-sm-9">
					<button type="submit" class="btn btn-primary">
						<i class="fa fa-check"></i>
						<?php 
            echo I18N::translate('save');
            ?>
					</button>
				</div>
			</div>

		</form>
		<?php 
        }
    }
Example #3
0
    /**
     * Show and process a form to edit a story.
     */
    private function edit()
    {
        global $WT_TREE;
        if (Auth::isEditor($WT_TREE)) {
            if (Filter::postBool('save') && Filter::checkCsrf()) {
                $block_id = Filter::postInteger('block_id');
                if ($block_id) {
                    Database::prepare("UPDATE `##block` SET gedcom_id=?, xref=? WHERE block_id=?")->execute(array(Filter::postInteger('gedcom_id'), Filter::post('xref', WT_REGEX_XREF), $block_id));
                } else {
                    Database::prepare("INSERT INTO `##block` (gedcom_id, xref, module_name, block_order) VALUES (?, ?, ?, ?)")->execute(array(Filter::postInteger('gedcom_id'), Filter::post('xref', WT_REGEX_XREF), $this->getName(), 0));
                    $block_id = Database::getInstance()->lastInsertId();
                }
                $this->setBlockSetting($block_id, 'title', Filter::post('title'));
                $this->setBlockSetting($block_id, 'story_body', Filter::post('story_body'));
                $languages = Filter::postArray('lang');
                $this->setBlockSetting($block_id, 'languages', implode(',', $languages));
                $this->config();
            } else {
                $block_id = Filter::getInteger('block_id');
                $controller = new PageController();
                if ($block_id) {
                    $controller->setPageTitle(I18N::translate('Edit story'));
                    $title = $this->getBlockSetting($block_id, 'title');
                    $story_body = $this->getBlockSetting($block_id, 'story_body');
                    $xref = Database::prepare("SELECT xref FROM `##block` WHERE block_id=?")->execute(array($block_id))->fetchOne();
                } else {
                    $controller->setPageTitle(I18N::translate('Add a story'));
                    $title = '';
                    $story_body = '';
                    $xref = Filter::get('xref', WT_REGEX_XREF);
                }
                $controller->pageHeader()->addExternalJavascript(WT_AUTOCOMPLETE_JS_URL)->addInlineJavascript('autocomplete();');
                if (Module::getModuleByName('ckeditor')) {
                    CkeditorModule::enableEditor($controller);
                }
                $individual = Individual::getInstance($xref, $WT_TREE);
                ?>
				<ol class="breadcrumb small">
					<li><a href="admin.php"><?php 
                echo I18N::translate('Control panel');
                ?>
</a></li>
					<li><a href="admin_modules.php"><?php 
                echo I18N::translate('Module administration');
                ?>
</a></li>
					<li><a href="module.php?mod=<?php 
                echo $this->getName();
                ?>
&mod_action=admin_config"><?php 
                echo $this->getTitle();
                ?>
</a></li>
					<li class="active"><?php 
                echo $controller->getPageTitle();
                ?>
</li>
				</ol>

				<h1><?php 
                echo $controller->getPageTitle();
                ?>
</h1>

				<form class="form-horizontal" method="post" action="module.php?mod=<?php 
                echo $this->getName();
                ?>
&amp;mod_action=admin_edit">
					<?php 
                echo Filter::getCsrf();
                ?>
					<input type="hidden" name="save" value="1">
					<input type="hidden" name="block_id" value="<?php 
                echo $block_id;
                ?>
">
					<input type="hidden" name="gedcom_id" value="<?php 
                echo $WT_TREE->getTreeId();
                ?>
">

					<div class="form-group">
						<label for="title" class="col-sm-3 control-label">
							<?php 
                echo I18N::translate('Story title');
                ?>
						</label>
						<div class="col-sm-9">
							<input type="text" class="form-control" name="title" id="title" value="<?php 
                echo Filter::escapeHtml($title);
                ?>
">
						</div>
					</div>

					<div class="form-group">
						<label for="story_body" class="col-sm-3 control-label">
							<?php 
                echo I18N::translate('Story');
                ?>
						</label>
						<div class="col-sm-9">
							<textarea name="story_body" id="story_body" class="html-edit form-control" rows="10"><?php 
                echo Filter::escapeHtml($story_body);
                ?>
</textarea>
						</div>
					</div>

					<div class="form-group">
						<label for="xref" class="col-sm-3 control-label">
							<?php 
                echo I18N::translate('Individual');
                ?>
						</label>
						<div class="col-sm-9">
							<input data-autocomplete-type="INDI" type="text" name="xref" id="xref" size="4" value="<?php 
                echo $xref;
                ?>
">
							<?php 
                echo FunctionsPrint::printFindIndividualLink('xref');
                ?>
							<?php 
                if ($individual) {
                    ?>
								<?php 
                    echo $individual->formatList('span');
                    ?>
							<?php 
                }
                ?>
						</div>
					</div>

					<div class="form-group">
						<label for="xref" class="col-sm-3 control-label">
							<?php 
                echo I18N::translate('Show this block for which languages?');
                ?>
						</label>
						<div class="col-sm-9">
							<?php 
                echo FunctionsEdit::editLanguageCheckboxes('lang', explode(',', $this->getBlockSetting($block_id, 'languages')));
                ?>
						</div>
					</div>

					<div class="form-group">
						<div class="col-sm-offset-3 col-sm-9">
							<button type="submit" class="btn btn-primary">
								<i class="fa fa-check"></i>
								<?php 
                echo I18N::translate('save');
                ?>
							</button>
						</div>
					</div>

				</form>
				<?php 
            }
        } else {
            header('Location: ' . WT_BASE_URL);
        }
    }
Example #4
0
 /**
  * extract all places from the given record and insert them into the places table
  *
  * @param string $gid
  * @param int    $ged_id
  * @param string $gedrec
  */
 public static function updatePlaces($gid, $ged_id, $gedrec)
 {
     global $placecache;
     if (!isset($placecache)) {
         $placecache = array();
     }
     $personplace = array();
     // import all place locations, but not control info such as
     // 0 HEAD/1 PLAC or 0 _EVDEF/1 PLAC
     $pt = preg_match_all("/^[2-9] PLAC (.+)/m", $gedrec, $match, PREG_SET_ORDER);
     for ($i = 0; $i < $pt; $i++) {
         $place = trim($match[$i][1]);
         $lowplace = I18N::strtolower($place);
         //-- if we have already visited this place for this person then we don't need to again
         if (isset($personplace[$lowplace])) {
             continue;
         }
         $personplace[$lowplace] = 1;
         $places = explode(',', $place);
         //-- reverse the array to start at the highest level
         $secalp = array_reverse($places);
         $parent_id = 0;
         $search = true;
         foreach ($secalp as $place) {
             $place = trim($place);
             $key = strtolower(mb_substr($place, 0, 150) . "_" . $parent_id);
             //-- if this place has already been added then we don't need to add it again
             if (isset($placecache[$key])) {
                 $parent_id = $placecache[$key];
                 if (!isset($personplace[$key])) {
                     $personplace[$key] = 1;
                     // Use INSERT IGNORE as a (temporary) fix for https://bugs.launchpad.net/webtrees/+bug/582226
                     // It ignores places that utf8_unicode_ci consider to be the same (i.e. accents).
                     // For example Québec and Quebec
                     // We need a better solution that attaches multiple names to single places
                     Database::prepare("INSERT IGNORE INTO `##placelinks` (pl_p_id, pl_gid, pl_file) VALUES (?, ?, ?)")->execute(array($parent_id, $gid, $ged_id));
                 }
                 continue;
             }
             //-- only search the database while we are finding places in it
             if ($search) {
                 //-- check if this place and level has already been added
                 $tmp = Database::prepare("SELECT p_id FROM `##places` WHERE p_file = ? AND p_parent_id = ? AND p_place = LEFT(?, 150)")->execute(array($ged_id, $parent_id, $place))->fetchOne();
                 if ($tmp) {
                     $p_id = $tmp;
                 } else {
                     $search = false;
                 }
             }
             //-- if we are not searching then we have to insert the place into the db
             if (!$search) {
                 $std_soundex = Soundex::russell($place);
                 $dm_soundex = Soundex::daitchMokotoff($place);
                 Database::prepare("INSERT INTO `##places` (p_place, p_parent_id, p_file, p_std_soundex, p_dm_soundex) VALUES (LEFT(?, 150), ?, ?, ?, ?)")->execute(array($place, $parent_id, $ged_id, $std_soundex, $dm_soundex));
                 $p_id = Database::getInstance()->lastInsertId();
             }
             Database::prepare("INSERT IGNORE INTO `##placelinks` (pl_p_id, pl_gid, pl_file) VALUES (?, ?, ?)")->execute(array($p_id, $gid, $ged_id));
             //-- increment the level and assign the parent id for the next place level
             $parent_id = $p_id;
             $placecache[$key] = $p_id;
             $personplace[$key] = 1;
         }
     }
 }
 /**
  * Action from the configuration page
  */
 private function editSave()
 {
     if (Filter::checkCsrf()) {
         $block_id = Filter::postInteger('block_id');
         if ($block_id) {
             Database::prepare("UPDATE `##block` SET gedcom_id = NULLIF(:tree_id, '0'), block_order = :block_order WHERE block_id = :block_id")->execute(array('tree_id' => Filter::postInteger('gedcom_id'), 'block_order' => Filter::postInteger('block_order'), 'block_id' => $block_id));
         } else {
             Database::prepare("INSERT INTO `##block` (gedcom_id, module_name, block_order) VALUES (NULLIF(:tree_id, '0'), :module_name, :block_order)")->execute(array('tree_id' => Filter::postInteger('gedcom_id'), 'module_name' => $this->getName(), 'block_order' => Filter::postInteger('block_order')));
             $block_id = Database::getInstance()->lastInsertId();
         }
         $this->setBlockSetting($block_id, 'header', Filter::post('header'));
         $this->setBlockSetting($block_id, 'faqbody', Filter::post('faqbody'));
         $languages = Filter::postArray('lang');
         $this->setBlockSetting($block_id, 'languages', implode(',', $languages));
     }
 }