Example #1
0
 /**
  * Task@trigger
  */
 public function trigger()
 {
     $controller = new AjaxController();
     $controller->pageHeader();
     $task_name = Filter::get('task');
     $token_submitted = Filter::get('force');
     $token = $this->module->getSetting('MAJ_AT_FORCE_EXEC_TOKEN');
     $tasks = $this->provider->getTasksToRun($token == $token_submitted, $task_name);
     foreach ($tasks as $task) {
         $task->execute();
     }
 }
Example #2
0
namespace Fisharebest\Webtrees;

use Fisharebest\Webtrees\Controller\AjaxController;
use Fisharebest\Webtrees\Functions\FunctionsImport;
use PDOException;
define('WT_SCRIPT_NAME', 'import.php');
require './includes/session.php';
// Don't use ged=XX as we want to be able to run without changing the current gedcom.
// This will let us load several gedcoms together, or to edit one while loading another.
$gedcom_id = Filter::getInteger('gedcom_id');
$tree = Tree::findById($gedcom_id);
if (!$tree || !Auth::isManager($tree, Auth::user())) {
    http_response_code(403);
    return;
}
$controller = new AjaxController();
$controller->pageHeader();
// Don't allow the user to cancel the request.  We do not want to be left
// with an incomplete transaction.
ignore_user_abort(true);
// Run in a transaction
Database::beginTransaction();
// Only allow one process to import each gedcom at a time
Database::prepare("SELECT * FROM `##gedcom_chunk` WHERE gedcom_id=? FOR UPDATE")->execute(array($gedcom_id));
// What is the current import status?
$row = Database::prepare("SELECT" . " SUM(IF(imported, LENGTH(chunk_data), 0)) AS import_offset," . " SUM(LENGTH(chunk_data))                  AS import_total" . " FROM `##gedcom_chunk` WHERE gedcom_id=?")->execute(array($gedcom_id))->fetchOneRow();
if ($row->import_offset == $row->import_total) {
    Tree::findById($gedcom_id)->setPreference('imported', '1');
    // Finished?  Show the maintenance links, similar to admin_trees_manage.php
    Database::commit();
    $controller->addInlineJavascript('jQuery("#import' . $gedcom_id . '").addClass("hidden");' . 'jQuery("#actions' . $gedcom_id . '").removeClass("hidden");');
    /**
     * Render the Ajax response for the sortable table of Sosa family
     * @param AjaxController $controller
     */
    protected function renderFamSosaListIndi(AjaxController $controller)
    {
        global $WT_TREE;
        $listFamSosa = $this->sosa_provider->getFamilySosaListAtGeneration($this->generation);
        $this->view_bag->set('has_sosa', false);
        if (count($listFamSosa) > 0) {
            $this->view_bag->set('has_sosa', true);
            $table_id = 'table-sosa-fam-' . Uuid::uuid4();
            $this->view_bag->set('table_id', $table_id);
            $controller->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL)->addInlineJavascript('
                jQuery.fn.dataTableExt.oSort["unicode-asc"  ]=function(a,b) {return a.replace(/<[^<]*>/, "").localeCompare(b.replace(/<[^<]*>/, ""))};
				jQuery.fn.dataTableExt.oSort["unicode-desc" ]=function(a,b) {return b.replace(/<[^<]*>/, "").localeCompare(a.replace(/<[^<]*>/, ""))};
				jQuery.fn.dataTableExt.oSort["num-html-asc" ]=function(a,b) {a=parseFloat(a.replace(/<[^<]*>/, "")); b=parseFloat(b.replace(/<[^<]*>/, "")); return (a<b) ? -1 : (a>b ? 1 : 0);};
				jQuery.fn.dataTableExt.oSort["num-html-desc"]=function(a,b) {a=parseFloat(a.replace(/<[^<]*>/, "")); b=parseFloat(b.replace(/<[^<]*>/, "")); return (a>b) ? -1 : (a<b ? 1 : 0);};
        
                jQuery("#' . $table_id . '").dataTable( {
					dom: \'<"H"<"filtersH_' . $table_id . '"><"dt-clear">pf<"dt-clear">irl>t<"F"pl<"dt-clear"><"filtersF_' . $table_id . '">>\',
                    ' . I18N::datatablesI18N(array(16, 32, 64, 128, -1)) . ',
					jQueryUI: true,
					autoWidth: false,
					processing: true,
					retrieve: true,
					columns: [
						/* 0-Sosa */  	   { dataSort: 1, class: "center"},
		                /* 1-SOSA */ 	   { type: "num", visible: false },
						/* 2-Husb Givn */  { dataSort: 4},
						/* 3-Husb Surn */  { dataSort: 5},
						/* 4-GIVN,SURN */  { type: "unicode", visible: false},
						/* 5-SURN,GIVN */  { type: "unicode", visible: false},
						/* 6-Husb Age  */  { dataSort: 7, class: "center"},
						/* 7-AGE       */  { type: "num", visible: false},
						/* 8-Wife Givn */  { dataSort: 10},
						/* 9-Wife Surn */  { dataSort: 11},
						/* 10-GIVN,SURN */ { type: "unicode", visible: false},
						/* 11-SURN,GIVN */ { type: "unicode", visible: false},
						/* 12-Wife Age  */ { dataSort: 13, class: "center"},
						/* 13-AGE       */ { type: "num", visible: false},
						/* 14-Marr Date */ { dataSort: 15, class: "center"},
						/* 15-MARR:DATE */ { visible: false},
						/* 16-Marr Plac */ { type: "unicode", class: "center"},
						/* 17-Marr Sour */ { dataSort : 18, class: "center", visible: ' . (ModuleManager::getInstance()->isOperational(Constants::MODULE_MAJ_ISSOURCED_NAME) ? 'true' : 'false') . ' },
						/* 18-Sort Sour */ { visible: false},
						/* 19-Children  */ { dataSort: 20, class: "center"},
						/* 20-NCHI      */ { type: "num", visible: false},
						/* 21-MARR      */ { visible: false},
						/* 22-DEAT      */ { visible: false},
						/* 23-TREE      */ { visible: false}
					],
					sorting: [[0, "asc"]],
					displayLength: 16,
					pagingType: "full_numbers"
			   });
					
				jQuery("#' . $table_id . '")
				/* Hide/show parents */
				.on("click", ".btn-toggle-parents", function() {
					jQuery(this).toggleClass("ui-state-active");
					jQuery(".parents", jQuery(this).closest("table").DataTable().rows().nodes()).slideToggle();
				})
				/* Hide/show statistics */
				.on("click",  ".btn-toggle-statistics", function() {
					jQuery(this).toggleClass("ui-state-active");
					jQuery("#fam_list_table-charts_' . $table_id . '").slideToggle();
				})
				/* Filter buttons in table header */
				.on("click", "button[data-filter-column]", function() {
					var btn = $(this);
					// De-activate the other buttons in this button group
					btn.siblings().removeClass("ui-state-active");
					// Apply (or clear) this filter
					var col = jQuery("#' . $table_id . '").DataTable().column(btn.data("filter-column"));
					if (btn.hasClass("ui-state-active")) {
						btn.removeClass("ui-state-active");
						col.search("").draw();
					} else {
						btn.addClass("ui-state-active");
						col.search(btn.data("filter-value")).draw();
					}
				});					
				
				jQuery("#sosa-fam-list").css("visibility", "visible");
				
				jQuery("#btn-toggle-statistics-' . $table_id . '").click();
           ');
            $stats = new Stats($WT_TREE);
            $max_age = max($stats->oldestMarriageMaleAge(), $stats->oldestMarriageFemaleAge()) + 1;
            //-- init chart data
            $marr_by_age = array();
            for ($age = 0; $age <= $max_age; $age++) {
                $marr_by_age[$age] = '';
            }
            $birt_by_decade = array();
            $marr_by_decade = array();
            for ($year = 1550; $year < 2030; $year += 10) {
                $birt_by_decade[$year] = '';
                $marr_by_decade[$year] = '';
            }
            foreach ($listFamSosa as $sosa => $fid) {
                $sfamily = Family::getInstance($fid, $WT_TREE);
                if (!$sfamily || !$sfamily->canShow()) {
                    unset($sfamily[$sosa]);
                    continue;
                }
                $mdate = $sfamily->getMarriageDate();
                if (($husb = $sfamily->getHusband()) && ($hdate = $husb->getBirthDate()) && $hdate->isOK() && $mdate->isOK()) {
                    if (FunctionsPrint::isDateWithinChartsRange($hdate)) {
                        $birt_by_decade[(int) ($hdate->gregorianYear() / 10) * 10] .= $husb->getSex();
                    }
                    $hage = Date::getAge($hdate, $mdate, 0);
                    if ($hage >= 0 && $hage <= $max_age) {
                        $marr_by_age[$hage] .= $husb->getSex();
                    }
                }
                if (($wife = $sfamily->getWife()) && ($wdate = $wife->getBirthDate()) && $wdate->isOK() && $mdate->isOK()) {
                    if (FunctionsPrint::isDateWithinChartsRange($wdate)) {
                        $birt_by_decade[(int) ($wdate->gregorianYear() / 10) * 10] .= $wife->getSex();
                    }
                    $wage = Date::getAge($wdate, $mdate, 0);
                    if ($wage >= 0 && $wage <= $max_age) {
                        $marr_by_age[$wage] .= $wife->getSex();
                    }
                }
                if ($mdate->isOK() && FunctionsPrint::isDateWithinChartsRange($mdate) && $husb && $wife) {
                    $marr_by_decade[(int) ($mdate->gregorianYear() / 10) * 10] .= $husb->getSex() . $wife->getSex();
                }
                $listFamSosa[$sosa] = $sfamily;
            }
            $this->view_bag->set('sosa_list', $listFamSosa);
            $this->view_bag->set('chart_births', FunctionsPrintLists::chartByDecade($birt_by_decade, I18N::translate('Decade of birth')));
            $this->view_bag->set('chart_marriages', FunctionsPrintLists::chartByDecade($marr_by_decade, I18N::translate('Decade of marriage')));
            $this->view_bag->set('chart_ages', FunctionsPrintLists::chartByAge($marr_by_age, I18N::translate('Age in year of marriage')));
        }
        ViewFactory::make('SosaListFam', $this, $controller, $this->view_bag)->render();
    }
Example #4
0
    $ctype = Filter::get('ctype', 'gedcom|user', 'user');
} else {
    $ctype = 'gedcom';
}
// Get the blocks list
if ($ctype === 'user') {
    $blocks = FunctionsDb::getUserBlocks(Auth::id());
} else {
    $blocks = FunctionsDb::getTreeBlocks($WT_TREE->getTreeId());
}
$active_blocks = Module::getActiveBlocks($WT_TREE);
// The latest version is shown on the administration page.  This updates it every day.
Functions::fetchLatestVersion();
// We generate individual blocks using AJAX
if ($action === 'ajax') {
    $controller = new AjaxController();
    $controller->pageHeader();
    // Check we’re displaying an allowable block.
    $block_id = Filter::getInteger('block_id');
    if (array_key_exists($block_id, $blocks['main'])) {
        $module_name = $blocks['main'][$block_id];
    } elseif (array_key_exists($block_id, $blocks['side'])) {
        $module_name = $blocks['side'][$block_id];
    } else {
        return;
    }
    if (array_key_exists($module_name, $active_blocks)) {
        echo $active_blocks[$module_name]->getBlock($block_id);
    }
    return;
}
 /**
  * SosaConfig@computePartial
  */
 public function computePartial()
 {
     global $WT_TREE;
     $controller = new AjaxController();
     $controller->restrictAccess($this->canUpdate());
     $view_bag = new ViewBag();
     $view_bag->set('is_success', false);
     $user = User::find(Filter::getInteger('userid', -1));
     $indi = Individual::getInstance(Filter::get('pid', WT_REGEX_XREF), $WT_TREE);
     if ($user && $indi) {
         $calculator = new SosaCalculator($WT_TREE, $user);
         if ($calculator->computeFromIndividual($indi)) {
             $view_bag->set('is_success', true);
         }
     } else {
         $view_bag->set('error', I18N::translate('Non existing individual'));
     }
     ViewFactory::make('SosaComputeResult', $this, $controller, $view_bag)->render();
 }
Example #6
0
					if (ui.tab.data("loaded")) {
						event.preventDefault();
						return;
					}
					else {
						jQuery("#loading-indicator").addClass("loading-image");
					}
					ui.jqXHR.success(function() {
						ui.tab.data("loaded", true);
					});
				}
			});
		')->pageHeader();
    echo '<div id="statistics-page"><h2>', I18N::translate('Statistics'), '</h2>', '<div id="statistics_chart">', '<ul>', '<li><a href="statistics.php?ged=', $WT_TREE->getNameUrl(), '&amp;ajax=1&amp;tab=0">', '<span id="stats-indi">', I18N::translate('Individuals'), '</span></a></li>', '<li><a href="statistics.php?ged=', $WT_TREE->getNameUrl(), '&amp;ajax=1&amp;tab=1">', '<span id="stats-fam">', I18N::translate('Families'), '</span></a></li>', '<li><a href="statistics.php?ged=', $WT_TREE->getNameUrl(), '&amp;ajax=1&amp;tab=2">', '<span id="stats-other">', I18N::translate('Others'), '</span></a></li>', '<li><a href="statistics.php?ged=', $WT_TREE->getNameUrl(), '&amp;ajax=1&amp;tab=3">', '<span id="stats-own">', I18N::translate('Own charts'), '</span></a></li>', '</ul>', '<div id="loading-indicator" style="margin:auto;width:100%;"></div>', '</div>', '</div>', '<br><br>';
} else {
    $controller = new AjaxController();
    $controller->pageHeader()->addInlineJavascript('autocomplete();')->addInlineJavascript('jQuery("#loading-indicator").removeClass("loading-image");');
    $stats = new Stats($WT_TREE);
    if ($tab == 0) {
        echo '<fieldset>
		<legend>', I18N::translate('Total individuals: %s', $stats->totalIndividuals()), '</legend>
		<table class="facts_table">
			<tr>
				<td class="facts_label">', I18N::translate('Total males'), '</td>
				<td class="facts_label">', I18N::translate('Total females'), '</td>
				<td class="facts_label">', I18N::translate('Total living'), '</td>
				<td class="facts_label">', I18N::translate('Total dead'), '</td>
			</tr>
			<tr>
				<td class="facts_value" align="center">', $stats->totalSexMales(), '</td>
				<td class="facts_value" align="center">', $stats->totalSexFemales(), '</td>
 /**
  * AdminConfig@generateToken
  *
  * Ajax call to generate a new token. Display the token, if generated.
  * Tokens call only be generated by a site administrator.
  *
  */
 public function generateToken()
 {
     $controller = new AjaxController();
     $controller->restrictAccess(Auth::isAdmin());
     $token = Functions::generateRandomToken();
     $this->module->setSetting('MAJ_AT_FORCE_EXEC_TOKEN', $token);
     Log::addConfigurationLog($this->module->getTitle() . ' : New token generated.');
     $controller->pageHeader();
     echo $token;
 }