Exemple #1
0
define('WT_SCRIPT_NAME', 'index_edit.php');
require './includes/session.php';
$controller = new WT_Controller_Ajax();
// Only one of $user_id and $gedcom_id should be set
$user_id = WT_Filter::get('user_id', WT_REGEX_INTEGER, WT_Filter::post('user_id', WT_REGEX_INTEGER));
if ($user_id) {
    $gedcom_id = null;
} else {
    $gedcom_id = WT_Filter::get('gedcom_id', WT_REGEX_INTEGER, WT_Filter::post('gedcom_id', WT_REGEX_INTEGER));
}
// Only an admin can edit the "default" page
// Only managers can edit the "home page"
// Only a user or an admin can edit a user’s "my page"
if ($gedcom_id < 0 && !Auth::isAdmin() || $gedcom_id > 0 && !Auth::isManager(WT_Tree::get($gedcom_id)) || $user_id && Auth::id() != $user_id && !Auth::isAdmin()) {
    $controller->pageHeader();
    $controller->addInlineJavascript('window.location.reload();');
    exit;
}
$action = WT_Filter::get('action');
if (isset($_REQUEST['main'])) {
    $main = $_REQUEST['main'];
} else {
    $main = array();
}
if (isset($_REQUEST['right'])) {
    $right = $_REQUEST['right'];
} else {
    $right = array();
}
// Define all the icons we're going to use
$IconUarrow = 'icon-uarrow';
Exemple #2
0
// This will let us load several gedcoms together, or to edit one while loading another.
$gedcom_id = WT_Filter::getInteger('gedcom_id');
// 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
WT_DB::exec("START TRANSACTION");
// Only allow one process to import each gedcom at a time
WT_DB::prepare("SELECT * FROM `##gedcom_chunk` WHERE gedcom_id=? FOR UPDATE")->execute(array($gedcom_id));
// What is the current import status?
$row = WT_DB::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) {
    set_gedcom_setting($gedcom_id, 'imported', true);
    // Finished?  Show the maintenance links, similar to admin_trees_manage.php
    WT_DB::exec("COMMIT");
    $controller->addInlineJavascript('jQuery("#import' . $gedcom_id . '").toggle();' . 'jQuery("#actions' . $gedcom_id . '").toggle();');
    exit;
}
// Calculate progress so far
$percent = 100 * ($row->import_offset / $row->import_total);
$status = WT_I18N::translate('Loading data from GEDCOM: %.1f%%', $percent);
echo '<div id="progressbar', $gedcom_id, '"><div style="position:absolute;">', $status, '</div></div>';
$controller->addInlineJavascript('jQuery("#progressbar' . $gedcom_id . '").progressbar({value: ' . round($percent, 1) . '});');
$first_time = $row->import_offset == 0;
// Run for one second.  This keeps the resource requirements low.
for ($end_time = microtime(true) + 1.0; microtime(true) < $end_time;) {
    $data = WT_DB::prepare("SELECT gedcom_chunk_id, REPLACE(chunk_data, '\r', '\n') AS chunk_data" . " FROM `##gedcom_chunk`" . " WHERE gedcom_id=? AND NOT imported" . " ORDER BY gedcom_chunk_id" . " LIMIT 1")->execute(array($gedcom_id))->fetchOneRow();
    // If we are at the start position, do some tidying up
    if ($first_time) {
        $keep_media = WT_Filter::getBool('keep_media' . $gedcom_id);
        // Delete any existing genealogical data