18c2e8227SGreg Roach<?php 28c2e8227SGreg Roachnamespace Fisharebest\Webtrees; 38c2e8227SGreg Roach 48c2e8227SGreg Roach/** 58c2e8227SGreg Roach * webtrees: online genealogy 68c2e8227SGreg Roach * Copyright (C) 2015 webtrees development team 78c2e8227SGreg Roach * This program is free software: you can redistribute it and/or modify 88c2e8227SGreg Roach * it under the terms of the GNU General Public License as published by 98c2e8227SGreg Roach * the Free Software Foundation, either version 3 of the License, or 108c2e8227SGreg Roach * (at your option) any later version. 118c2e8227SGreg Roach * This program is distributed in the hope that it will be useful, 128c2e8227SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 138c2e8227SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 148c2e8227SGreg Roach * GNU General Public License for more details. 158c2e8227SGreg Roach * You should have received a copy of the GNU General Public License 168c2e8227SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 178c2e8227SGreg Roach */ 188c2e8227SGreg Roach 198c2e8227SGreg Roachuse Zend_Session; 208c2e8227SGreg Roach 218c2e8227SGreg Roach/** 228c2e8227SGreg Roach * Class InteractiveTreeModule 238c2e8227SGreg Roach * Tip : you could change the number of generations loaded before ajax calls both in individual page and in treeview page to optimize speed and server load 248c2e8227SGreg Roach */ 258c2e8227SGreg Roachclass InteractiveTreeModule extends Module implements ModuleTabInterface { 268c2e8227SGreg Roach var $headers; // CSS and script to include in the top of <head> section, before theme’s CSS 278c2e8227SGreg Roach var $js; // the TreeViewHandler javascript 288c2e8227SGreg Roach 298c2e8227SGreg Roach /** {@inheritdoc} */ 308c2e8227SGreg Roach public function getTitle() { 318c2e8227SGreg Roach return /* I18N: Name of a module */ I18N::translate('Interactive tree'); 328c2e8227SGreg Roach } 338c2e8227SGreg Roach 348c2e8227SGreg Roach /** {@inheritdoc} */ 358c2e8227SGreg Roach public function getDescription() { 368c2e8227SGreg Roach return /* I18N: Description of the “Interactive tree” module */ I18N::translate('An interactive tree, showing all the ancestors and descendants of an individual.'); 378c2e8227SGreg Roach } 388c2e8227SGreg Roach 398c2e8227SGreg Roach /** {@inheritdoc} */ 408c2e8227SGreg Roach public function defaultTabOrder() { 418c2e8227SGreg Roach return 68; 428c2e8227SGreg Roach } 438c2e8227SGreg Roach 448c2e8227SGreg Roach /** {@inheritdoc} */ 458c2e8227SGreg Roach public function getTabContent() { 468c2e8227SGreg Roach global $controller; 478c2e8227SGreg Roach 488c2e8227SGreg Roach $tv = new TreeView('tvTab'); 498c2e8227SGreg Roach list($html, $js) = $tv->drawViewport($controller->record, 3); 508c2e8227SGreg Roach return 518c2e8227SGreg Roach '<script src="' . $this->js() . '"></script>' . 528c2e8227SGreg Roach '<script src="' . WT_JQUERYUI_TOUCH_PUNCH_URL . '"></script>' . 538c2e8227SGreg Roach '<script>' . $js . '</script>' . 548c2e8227SGreg Roach $html; 558c2e8227SGreg Roach } 568c2e8227SGreg Roach 578c2e8227SGreg Roach /** {@inheritdoc} */ 588c2e8227SGreg Roach public function hasTabContent() { 598c2e8227SGreg Roach return !Auth::isSearchEngine(); 608c2e8227SGreg Roach } 618c2e8227SGreg Roach 628c2e8227SGreg Roach /** {@inheritdoc} */ 638c2e8227SGreg Roach public function isGrayedOut() { 648c2e8227SGreg Roach return false; 658c2e8227SGreg Roach } 668c2e8227SGreg Roach 678c2e8227SGreg Roach /** {@inheritdoc} */ 688c2e8227SGreg Roach public function canLoadAjax() { 698c2e8227SGreg Roach return true; 708c2e8227SGreg Roach } 718c2e8227SGreg Roach 728c2e8227SGreg Roach /** {@inheritdoc} */ 738c2e8227SGreg Roach public function getPreLoadContent() { 748c2e8227SGreg Roach // We cannot use jQuery("head").append(<link rel="stylesheet" ...as jQuery is not loaded at this time 758c2e8227SGreg Roach return 768c2e8227SGreg Roach '<script> 778c2e8227SGreg Roach if (document.createStyleSheet) { 788c2e8227SGreg Roach document.createStyleSheet("' . $this->css() . '"); // For Internet Explorer 798c2e8227SGreg Roach } else { 808c2e8227SGreg Roach var newSheet=document.createElement("link"); 818c2e8227SGreg Roach newSheet.setAttribute("rel","stylesheet"); 828c2e8227SGreg Roach newSheet.setAttribute("type","text/css"); 838c2e8227SGreg Roach newSheet.setAttribute("href","' . $this->css() . '"); 848c2e8227SGreg Roach document.getElementsByTagName("head")[0].appendChild(newSheet); 858c2e8227SGreg Roach } 868c2e8227SGreg Roach </script>'; 878c2e8227SGreg Roach } 888c2e8227SGreg Roach 898c2e8227SGreg Roach /** {@inheritdoc} */ 908c2e8227SGreg Roach public function modAction($mod_action) { 91*24ec66ceSGreg Roach global $controller, $WT_TREE; 92*24ec66ceSGreg Roach 938c2e8227SGreg Roach switch ($mod_action) { 948c2e8227SGreg Roach case 'treeview': 958c2e8227SGreg Roach $controller = new ChartController; 968c2e8227SGreg Roach $tv = new TreeView('tv'); 978c2e8227SGreg Roach ob_start(); 988c2e8227SGreg Roach 998c2e8227SGreg Roach $person = $controller->getSignificantIndividual(); 1008c2e8227SGreg Roach 1018c2e8227SGreg Roach list($html, $js) = $tv->drawViewport($person, 4); 1028c2e8227SGreg Roach 1038c2e8227SGreg Roach $controller 1048c2e8227SGreg Roach ->setPageTitle(I18N::translate('Interactive tree of %s', $person->getFullName())) 1058c2e8227SGreg Roach ->pageHeader() 1068c2e8227SGreg Roach ->addExternalJavascript($this->js()) 1078c2e8227SGreg Roach ->addExternalJavascript(WT_JQUERYUI_TOUCH_PUNCH_URL) 1088c2e8227SGreg Roach ->addInlineJavascript($js) 1098c2e8227SGreg Roach ->addInlineJavascript(' 1108c2e8227SGreg Roach if (document.createStyleSheet) { 1118c2e8227SGreg Roach document.createStyleSheet("' . $this->css() . '"); // For Internet Explorer 1128c2e8227SGreg Roach } else { 1138c2e8227SGreg Roach jQuery("head").append(\'<link rel="stylesheet" type="text/css" href="' . $this->css() . '">\'); 1148c2e8227SGreg Roach } 1158c2e8227SGreg Roach '); 1168c2e8227SGreg Roach echo $html; 1178c2e8227SGreg Roach break; 1188c2e8227SGreg Roach 1198c2e8227SGreg Roach case 'getDetails': 1208c2e8227SGreg Roach Zend_Session::writeClose(); 1218c2e8227SGreg Roach header('Content-Type: text/html; charset=UTF-8'); 1228c2e8227SGreg Roach $pid = Filter::get('pid', WT_REGEX_XREF); 1238c2e8227SGreg Roach $i = Filter::get('instance'); 1248c2e8227SGreg Roach $tv = new TreeView($i); 125*24ec66ceSGreg Roach $individual = Individual::getInstance($pid, $WT_TREE); 1268c2e8227SGreg Roach if ($individual) { 1278c2e8227SGreg Roach echo $tv->getDetails($individual); 1288c2e8227SGreg Roach } 1298c2e8227SGreg Roach break; 1308c2e8227SGreg Roach 1318c2e8227SGreg Roach case 'getPersons': 1328c2e8227SGreg Roach Zend_Session::writeClose(); 1338c2e8227SGreg Roach header('Content-Type: text/html; charset=UTF-8'); 1348c2e8227SGreg Roach $q = Filter::get('q'); 1358c2e8227SGreg Roach $i = Filter::get('instance'); 1368c2e8227SGreg Roach $tv = new TreeView($i); 1378c2e8227SGreg Roach echo $tv->getPersons($q); 1388c2e8227SGreg Roach break; 1398c2e8227SGreg Roach 1408c2e8227SGreg Roach default: 1418c2e8227SGreg Roach http_response_code(404); 1428c2e8227SGreg Roach break; 1438c2e8227SGreg Roach } 1448c2e8227SGreg Roach } 1458c2e8227SGreg Roach 1468c2e8227SGreg Roach /** 1478c2e8227SGreg Roach * @return string 1488c2e8227SGreg Roach */ 1498c2e8227SGreg Roach public function css() { 1508c2e8227SGreg Roach return WT_STATIC_URL . WT_MODULES_DIR . $this->getName() . '/css/treeview.css'; 1518c2e8227SGreg Roach } 1528c2e8227SGreg Roach 1538c2e8227SGreg Roach /** 1548c2e8227SGreg Roach * @return string 1558c2e8227SGreg Roach */ 1568c2e8227SGreg Roach public function js() { 1578c2e8227SGreg Roach return WT_STATIC_URL . WT_MODULES_DIR . $this->getName() . '/js/treeview.js'; 1588c2e8227SGreg Roach } 1598c2e8227SGreg Roach} 160