Ejemplo n.º 1
0
    /**
     * This is a general purpose hook, allowing modules to respond to routes
     * of the form module.php?mod=FOO&mod_action=BAR
     *
     * @param string $mod_action
     */
    public function modAction($mod_action)
    {
        global $controller, $WT_TREE;
        switch ($mod_action) {
            case 'treeview':
                $controller = new ChartController();
                $tv = new TreeView('tv');
                ob_start();
                $person = $controller->getSignificantIndividual();
                list($html, $js) = $tv->drawViewport($person, 4);
                $controller->setPageTitle(I18N::translate('Interactive tree of %s', $person->getFullName()))->pageHeader()->addExternalJavascript($this->js())->addExternalJavascript(WT_JQUERYUI_TOUCH_PUNCH_URL)->addInlineJavascript($js)->addInlineJavascript('
					if (document.createStyleSheet) {
						document.createStyleSheet("' . $this->css() . '"); // For Internet Explorer
					} else {
						jQuery("head").append(\'<link rel="stylesheet" type="text/css" href="' . $this->css() . '">\');
					}
				');
                echo $html;
                break;
            case 'getDetails':
                header('Content-Type: text/html; charset=UTF-8');
                $pid = Filter::get('pid', WT_REGEX_XREF);
                $i = Filter::get('instance');
                $tv = new TreeView($i);
                $individual = Individual::getInstance($pid, $WT_TREE);
                if ($individual) {
                    echo $tv->getDetails($individual);
                }
                break;
            case 'getPersons':
                header('Content-Type: text/html; charset=UTF-8');
                $q = Filter::get('q');
                $i = Filter::get('instance');
                $tv = new TreeView($i);
                echo $tv->getPersons($q);
                break;
            default:
                http_response_code(404);
                break;
        }
    }
Ejemplo n.º 2
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 $WT_TREE, $ctype, $controller;
     $PEDIGREE_ROOT_ID = $WT_TREE->getPreference('PEDIGREE_ROOT_ID');
     $gedcomid = $WT_TREE->getUserPreference(Auth::user(), 'gedcomid');
     $details = $this->getBlockSetting($block_id, 'details', '0');
     $type = $this->getBlockSetting($block_id, 'type', 'pedigree');
     $pid = $this->getBlockSetting($block_id, 'pid', Auth::check() ? $gedcomid ? $gedcomid : $PEDIGREE_ROOT_ID : $PEDIGREE_ROOT_ID);
     foreach (array('details', 'type', 'pid', 'block') as $name) {
         if (array_key_exists($name, $cfg)) {
             ${$name} = $cfg[$name];
         }
     }
     $person = Individual::getInstance($pid, $WT_TREE);
     if (!$person) {
         $pid = $PEDIGREE_ROOT_ID;
         $this->setBlockSetting($block_id, 'pid', $pid);
         $person = Individual::getInstance($pid, $WT_TREE);
     }
     $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 = '';
     }
     if ($person) {
         $content = '<table cellspacing="0" cellpadding="0" border="0"><tr>';
         switch ($type) {
             case 'pedigree':
                 $title .= I18N::translate('Pedigree of %s', $person->getFullName());
                 $chartController = new HourglassController($person->getXref(), $details, false);
                 $controller->addInlineJavascript($chartController->setupJavascript());
                 $content .= '<td>';
                 ob_start();
                 FunctionsPrint::printPedigreePerson($person, $details);
                 $content .= ob_get_clean();
                 $content .= '</td>';
                 $content .= '<td>';
                 ob_start();
                 $chartController->printPersonPedigree($person, 1);
                 $content .= ob_get_clean();
                 $content .= '</td>';
                 break;
             case 'descendants':
                 $title .= I18N::translate('Descendants of %s', $person->getFullName());
                 $chartController = new HourglassController($person->getXref(), $details, false);
                 $controller->addInlineJavascript($chartController->setupJavascript());
                 $content .= '<td>';
                 ob_start();
                 $chartController->printDescendency($person, 1, false);
                 $content .= ob_get_clean();
                 $content .= '</td>';
                 break;
             case 'hourglass':
                 $title .= I18N::translate('Hourglass chart of %s', $person->getFullName());
                 $chartController = new HourglassController($person->getXref(), $details, false);
                 $controller->addInlineJavascript($chartController->setupJavascript());
                 $content .= '<td>';
                 ob_start();
                 $chartController->printDescendency($person, 1, false);
                 $content .= ob_get_clean();
                 $content .= '</td>';
                 $content .= '<td>';
                 ob_start();
                 $chartController->printPersonPedigree($person, 1);
                 $content .= ob_get_clean();
                 $content .= '</td>';
                 break;
             case 'treenav':
                 $title .= I18N::translate('Interactive tree of %s', $person->getFullName());
                 $mod = new InteractiveTreeModule(WT_MODULES_DIR . 'tree');
                 $tv = new TreeView();
                 $content .= '<td>';
                 $content .= '<script>jQuery("head").append(\'<link rel="stylesheet" href="' . $mod->css() . '" type="text/css" />\');</script>';
                 $content .= '<script src="' . $mod->js() . '"></script>';
                 list($html, $js) = $tv->drawViewport($person, 2);
                 $content .= $html . '<script>' . $js . '</script>';
                 $content .= '</td>';
                 break;
         }
         $content .= '</tr></table>';
     } else {
         $content = I18N::translate('You must select an individual and chart type in the block configuration settings.');
     }
     if ($template) {
         return Theme::theme()->formatBlock($id, $title, $class, $content);
     } else {
         return $content;
     }
 }