1<?php 2namespace Fisharebest\Webtrees; 3 4/** 5 * webtrees: online genealogy 6 * Copyright (C) 2015 webtrees development team 7 * This program is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19/** 20 * Class ChartsBlockModule 21 */ 22class ChartsBlockModule extends Module implements ModuleBlockInterface { 23 /** {@inheritdoc} */ 24 public function getTitle() { 25 return /* I18N: Name of a module/block */ I18N::translate('Charts'); 26 } 27 28 /** {@inheritdoc} */ 29 public function getDescription() { 30 return /* I18N: Description of the “Charts” module */ I18N::translate('An alternative way to display charts.'); 31 } 32 33 /** {@inheritdoc} */ 34 public function getBlock($block_id, $template = true, $cfg = null) { 35 global $WT_TREE, $ctype, $controller; 36 37 $PEDIGREE_ROOT_ID = $WT_TREE->getPreference('PEDIGREE_ROOT_ID'); 38 $gedcomid = $WT_TREE->getUserPreference(Auth::user(), 'gedcomid'); 39 40 $details = get_block_setting($block_id, 'details', '0'); 41 $type = get_block_setting($block_id, 'type', 'pedigree'); 42 $pid = get_block_setting($block_id, 'pid', Auth::check() ? ($gedcomid ? $gedcomid : $PEDIGREE_ROOT_ID) : $PEDIGREE_ROOT_ID); 43 44 if ($cfg) { 45 foreach (array('details', 'type', 'pid', 'block') as $name) { 46 if (array_key_exists($name, $cfg)) { 47 $$name = $cfg[$name]; 48 } 49 } 50 } 51 52 $person = Individual::getInstance($pid, $WT_TREE); 53 if (!$person) { 54 $pid = $PEDIGREE_ROOT_ID; 55 set_block_setting($block_id, 'pid', $pid); 56 $person = Individual::getInstance($pid, $WT_TREE); 57 } 58 59 $id = $this->getName() . $block_id; 60 $class = $this->getName() . '_block'; 61 if ($ctype == 'gedcom' && Auth::isManager($WT_TREE) || $ctype == 'user' && Auth::check()) { 62 $title = '<i class="icon-admin" title="' . I18N::translate('Configure') . '" onclick="modalDialog(\'block_edit.php?block_id=' . $block_id . '\', \'' . $this->getTitle() . '\');"></i>'; 63 } else { 64 $title = ''; 65 } 66 67 if ($person) { 68 $content = '<table cellspacing="0" cellpadding="0" border="0"><tr>'; 69 switch ($type) { 70 case 'pedigree': 71 $title .= I18N::translate('Pedigree of %s', $person->getFullName()); 72 $chartController = new HourglassController($person->getXref(), $details, false); 73 $controller->addInlineJavascript($chartController->setupJavascript()); 74 $content .= '<td valign="middle">'; 75 ob_start(); 76 print_pedigree_person($person, $details); 77 $content .= ob_get_clean(); 78 $content .= '</td>'; 79 $content .= '<td valign="middle">'; 80 ob_start(); 81 $chartController->printPersonPedigree($person, 1); 82 $content .= ob_get_clean(); 83 $content .= '</td>'; 84 break; 85 case 'descendants': 86 $title .= I18N::translate('Descendants of %s', $person->getFullName()); 87 $chartController = new HourglassController($person->getXref(), $details, false); 88 $controller->addInlineJavascript($chartController->setupJavascript()); 89 $content .= '<td valign="middle">'; 90 ob_start(); 91 $chartController->printDescendency($person, 1, false); 92 $content .= ob_get_clean(); 93 $content .= '</td>'; 94 break; 95 case 'hourglass': 96 $title .= I18N::translate('Hourglass chart of %s', $person->getFullName()); 97 $chartController = new HourglassController($person->getXref(), $details, false); 98 $controller->addInlineJavascript($chartController->setupJavascript()); 99 $content .= '<td valign="middle">'; 100 ob_start(); 101 $chartController->printDescendency($person, 1, false); 102 $content .= ob_get_clean(); 103 $content .= '</td>'; 104 $content .= '<td valign="middle">'; 105 ob_start(); 106 $chartController->printPersonPedigree($person, 1); 107 $content .= ob_get_clean(); 108 $content .= '</td>'; 109 break; 110 case 'treenav': 111 $title .= I18N::translate('Interactive tree of %s', $person->getFullName()); 112 $mod = new InteractiveTreeModule(WT_MODULES_DIR . 'tree'); 113 $tv = new TreeView; 114 $content .= '<td>'; 115 $content .= '<script>jQuery("head").append(\'<link rel="stylesheet" href="' . $mod->css() . '" type="text/css" />\');</script>'; 116 $content .= '<script src="' . $mod->js() . '"></script>'; 117 list($html, $js) = $tv->drawViewport($person, 2); 118 $content .= $html . '<script>' . $js . '</script>'; 119 $content .= '</td>'; 120 break; 121 } 122 $content .= '</tr></table>'; 123 } else { 124 $content = I18N::translate('You must select an individual and chart type in the block configuration settings.'); 125 } 126 127 if ($template) { 128 return Theme::theme()->formatBlock($id, $title, $class, $content); 129 } else { 130 return $content; 131 } 132 } 133 134 /** {@inheritdoc} */ 135 public function loadAjax() { 136 return true; 137 } 138 139 /** {@inheritdoc} */ 140 public function isUserBlock() { 141 return true; 142 } 143 144 /** {@inheritdoc} */ 145 public function isGedcomBlock() { 146 return true; 147 } 148 149 /** {@inheritdoc} */ 150 public function configureBlock($block_id) { 151 global $WT_TREE, $controller; 152 153 $PEDIGREE_ROOT_ID = $WT_TREE->getPreference('PEDIGREE_ROOT_ID'); 154 $gedcomid = $WT_TREE->getUserPreference(Auth::user(), 'gedcomid'); 155 156 if (Filter::postBool('save') && Filter::checkCsrf()) { 157 set_block_setting($block_id, 'details', Filter::postBool('details')); 158 set_block_setting($block_id, 'type', Filter::post('type', 'pedigree|descendants|hourglass|treenav', 'pedigree')); 159 set_block_setting($block_id, 'pid', Filter::post('pid', WT_REGEX_XREF)); 160 } 161 162 $details = get_block_setting($block_id, 'details', '0'); 163 $type = get_block_setting($block_id, 'type', 'pedigree'); 164 $pid = get_block_setting($block_id, 'pid', Auth::check() ? ($gedcomid ? $gedcomid : $PEDIGREE_ROOT_ID) : $PEDIGREE_ROOT_ID); 165 166 $controller 167 ->addExternalJavascript(WT_AUTOCOMPLETE_JS_URL) 168 ->addInlineJavascript('autocomplete();'); 169 ?> 170 <tr> 171 <td colspan="2"> 172 <?php echo I18N::translate('This block allows a pedigree, descendancy, or hourglass chart to appear on your “My page” or the “Home page”. Because of space limitations, the charts should be placed only on the left side of the page.<br><br>When this block appears on the “Home page”, the root individual and the type of chart to be displayed are determined by the administrator. When this block appears on the user’s “My page”, these options are determined by the user.<br><br>The behavior of these charts is identical to their behavior when they are called up from the menus. Click on the box of an individual to see more details about them.'); ?> 173 </td> 174 </tr> 175 <tr> 176 <td class="descriptionbox wrap width33"><?php echo I18N::translate('Chart type'); ?></td> 177 <td class="optionbox"> 178 <?php echo select_edit_control('type', 179 array( 180 'pedigree' => I18N::translate('Pedigree'), 181 'descendants' => I18N::translate('Descendants'), 182 'hourglass' => I18N::translate('Hourglass chart'), 183 'treenav' => I18N::translate('Interactive tree')), 184 null, $type); ?> 185 </td> 186 </tr> 187 <tr> 188 <td class="descriptionbox wrap width33"><?php echo I18N::translate('Show details'); ?></td> 189 <td class="optionbox"> 190 <?php echo edit_field_yes_no('details', $details); ?> 191 </td> 192 </tr> 193 <tr> 194 <td class="descriptionbox wrap width33"><?php echo I18N::translate('Individual'); ?></td> 195 <td class="optionbox"> 196 <input data-autocomplete-type="INDI" type="text" name="pid" id="pid" value="<?php echo $pid; ?>" size="5"> 197 <?php 198 echo print_findindi_link('pid'); 199 $root = Individual::getInstance($pid, $WT_TREE); 200 if ($root) { 201 echo ' <span class="list_item">', $root->getFullName(), $root->format_first_major_fact(WT_EVENTS_BIRT, 1), '</span>'; 202 } 203 ?> 204 </td> 205 </tr> 206 <?php 207 } 208} 209