This is a TNG mod directive file
%name:Gedcom Import Purge%
%version:13.0.0.5e%
%description: Changes the Gedcom Import to purge fewer places, mark medialinks created by a Gedcom Import, (optionally) purge medialinks marked by a previous Gedcom Import, and (optionally) suppress the creation of citation medialinks.
<p>The two optional actions are controlled by checkboxes on the Gedcom Import kickoff form.</p>
<p style='border:2px solid black;padding-left:6px;' class='databack'>To keep track of imported Medialinks,
this mod requires a new database field in the Medialinks table. <i>After the very first time</i> that you install the mod,
<a href="rrgedcomimportpurge_dbsetup.php?return=mm" target="_blank">create the database field</a>,
which is called <i>createdfromgedcom</i>.<br>
You can also <a href="rrgedcomimportpurge_dbsetup.php?return=mm" target="_blank">remove the database field</a> if you plan to stop using this mod.</p>
<p>Note that the first time you invoke a Gedcom Import after you install this mod, the <i>createdfromgedcom</i> flags <i>will not have been set</i>,
and old medialinks will therefore not be purged, even if the checkbox that says to purge old medialinks is checked.
%
%wikipage:Gedcom_Import_Purge%
%author:Robin Richmond:https://tng.lythgoes.net/wiki/index.php?title=User:Robinrichm%
**********************************
*** Revision History ***
v13.0.0.5e 02 Nov 2020
* Had to change a target Location to accommodate a underlying change (whose purpose I don't understand) in TNGv13.0.1
v13.0.0.5d 28 Oct 2020
* Fixed a bug that prevented the database utility from deleting the new database field.
* Handled the missing FromGedcom field error in the Gedcom Import process and in Edit Cemeteries.
This required changes to most of the target files.
- The Gedcom Import kickoff form and the Cemetery edit page both now have links to the
database setup program, and load it into the same browser tab.
- The three links to the database setup program (including from the .cfg file description) pass a "return"
parameter, and the setup program can be closed (to return to MM) only if it was invoked by MM.
v13.0.0.5c 28 Oct 2020
* Moved the utility that creates the database field into the .cfg file as %newfile to fix the reference to the language file.
v13.0.0.5b 27 Aug 2020
* Changed the popup help text (in the Import/Export help file) for the Citation Medialinks option.
* Fixed the missing language strings in the configuration file.
v13.0.0.5a 8 Aug 2020
* Changed the last admin_gedimport.php target location to handle the new function tng_adminfooter.
* Upgraded to the TNGv13 version of the Inner Mod Menu mod.
v5a 15 Jan 2019
# Upgraded to version 4 of the shared mod libraries.
# Don't purge places if there is more than one tree but only one places list, since
purging places without regard to their use in other trees can break external reference
from records in those trees.
# The Inner Mod Menu links to the Wiki article rather than to the help file to describe what the mod does.
# Added a document.ready function in admin_importconfig.php to move a footnote from the bottom
of the page to a position right below the text it refers to. The insertion of the Gedcom Import
mods made that footnote too far from where it needs to be.
# Added a checkbox to the Gedcom Kickoff import form that can suppress the creation of citation medialinks.
# Fixed two missing %end:% tags that break installation in TNGv12.3
v5 1 Oct 18
- Modifies the Place purge process so that it does not purge places on sites that have mulitple
trees and have one shared Places list. Purging places from a shared Places list can delete
places that are used by other trees.
- Inserts an Inner Mod Menu
- Moves the mod parameters to TNG system options in a Mod Settings Block
- Modifes the Edit Media form to allow the user to set or unset the new "createdfromgedcom" flag.
o A new "Purge on Gedcom" checkbox is displayed for each MediaLink associated with the current Media item.
o The new checkbox is in the HTML Medialinks table, in a new column next to the "Show" checkbox and column
(where "Show" means "Always show this media item, even if it linked to a person that the current
user is not allowed to see")
v4 7 Apr 2018 for TNGv12
- No functional changes
- Updated the search text for gedimport_misc.php location 5 to remove a variable that is no longer
needed in a global statement.
- Updated the cust_text.php search strings and the author tag
- Added a note tag referring to the database setup
- Updated the author tag.
v3p 07 Nov 2017
- Removed the second line from the cust_text.php target location search string
v3a 14 Jul 2017
- The medialinks purge wasn't reporting the correct number of unpurged links. It always reported 1.
- The places purge wasn't purging places with null placelevel or zoom values. It only looked for 0.
v3 10 May 2017
- Fixed and cleaned up $admtext variables
- The DisplayModNames mod is now optional
- The info button class has been pulled into an embedded stylesheet, eliminating
a dependency on the Blue Info Button mod
v2 25 May 2016
- Removed problematic but unnecessary code from the mod's database modification program.
More specifically... Sometimes, but not always, PHP resets the user session when it encounters a
a <script> tag whose script can't be found. Standard admin programs contain such a tag:
<script type="text/javascript" src="js/admin.js"></script>
which fails when the program is run from a mod subfolder.
Fortunately, that script isn't needed by the mod's database modification program.
- Actually, to avoid another instance of the same problem inside standard TNG code, I also
renamed that program and changed the mod to install it to the main TNG folder.
v1b - 27 Mar 2016
- Found a JavaScript bug; the submitClick validation function was not returning the value
returned by its call to the confirm function. It was just a warning, so it wasn't awful.
- Cleaned up the code by using (document).ready event handlers rather than events specified
in the form field HTML elements.
- Also uses more advanced jQuery selectors in the event handlers so that I don't have to
force ID attributes into existing form field HTML elements.
- Changed the Mod Parameters to strings rather than boolean values to be more tolerant of
data entry errors. Now "true" mean true, and anything else means false
v1a - 22 Feb 2016
- Uses Show Mod Names v2
***********************************************************************
***********************************************************************
%target:admin_dataimport.php%
*** The program that displays the kickoff form that starts the Gedcom Import process ***
*** Adds a checkbox that will cause the Gedcom Import to purge old medialinks.
*** o If there are 'createdfromgedcom' fields whose value is 1, then the new checkbox
*** is labeled "Purge Medialinks created by a previous Gedcom Import"
*** o If no 'createdfromgedcom' field values are set, then the then the new checkbox
*** is labeled "Purge all Medialinks"
*** Adds an information hyperlink next to the new Purge Medialinks checkbox.
%parameter:$GedcomImportPurge:%
%desc:This is just a dummy parameter to link you to
<b style='font-style:1.1em;'><a href='admin_importconfig.php?open=robin13&mod=GedcomImportPurge'>this mod's options</a></b>.
<p>This dummy parameter defaults to the empty string (); there is no point but no harm in changing it.</p>
%
**** Start with a fileexists directive that looks for the Mod Settings Blocks Include file,
**** and generate an error if that file is not present.
%fileexists:rrmodsettingsblocks.php:location1%
*** Dummy location guaranteed not to work
%location:<b style='color:red;'>***The <a href="https://tng.lythgoes.net/wiki/index.php?title=Mod_Settings_Blocks" target="_blank">Mod Settings Blocks</a> mod must be installed***</b>%
{{dummy search string}}
%end:%
%replace:%
{{dummy replacement string}}
%end:%
%label:location1%
%location:%
include("begin.php");
%end:%
%insert:after%
##### admin_dataimport.php, modified by ###Gedcom Import Purge, by Robin Richmond
# Adds a checkbox that controls the purging of old medialinks.
$GedcomImportPurge = ''; #Dummy mod parameter that links to the mod options
$tngModNames['Gedcom Import Purge']['admin_dataimport.php'] = '5e'; #Register this mod
########################################################
#Read custom language strings from a mods subfolder rather than from standard TNG custom text files.
$modfolder = 'gedcom_import_purge_v13.0.0.5e';
include("$modspath/$modfolder/languages/English_custtext.php");
if ($mylanguage != "languages/English" && file_exists("$modspath/$modfolder/{$mylanguage}_custtext.php"))
include("$modspath/$modfolder/{$mylanguage}_custtext.php");
#############################################################################
#Initialize the mod options
if (!isset($rrconfig['GedcomPurgeImportMedia'])) $rrconfig['GedcomPurgeImportMedia'] = '1';
if (!isset($rrconfig['GedcomPurgeMedialinks'])) $rrconfig['GedcomPurgeMedialinks'] = '1';
#############################################################################
%end:%
******* admin_dataimport.php Location 2 - New onclick event for the submit button.
%location:%
<script type="text/javascript" src="js/admin.js?v<?php echo $tng_version; ?>"></script>
%end:%
%insert:after%
<!-- ###Gedcom Import Purge Location 2: new document.ready function -->
<script>
////////////////////////////////////////////////////////////////////
/////////////////// Document.ready function ////////////////////////
$(function(){
//Check the Import Media checkbox if a mod parameter says to do so.
<?php
if ($rrconfig['GedcomPurgeImportMedia'])
echo "$(\"input[name='importmedia']\").prop('checked',true);\n";
?>
// Onclick event for the form submit button.
$(':submit').click(function() {
//It's possible but unlikely that the user would want to purge medialinks when the
//Import Media checkbox is unchecked.
if (!$("[name='importmedia']").is(':checked') && $("#rrPurgeMedialinks").is(':checked') )
return confirm ("<?php echo $admtext['rrgip-purgewarn']; ?>");
})
// Onclick event handler for the Import Media checkbox.
// If the Import Media checkbox is off then the Purge Media Links box should be unchecked.
// The user can recheck it, but isn't likely to do so.
$("input[name='importmedia']").click(function() {
if (!$(this).is(':checked'))
$('#rrPurgeMedialinks').attr('checked',false);
})
}); //End of (document).ready function
</script>
<!-- ###Gedcom Import Purge Location 2: End of insertion -->
%end:%
*************** admin_dataimport.php Location 3 - Insert an Inner Mod Menu
%location:%
$menu = doMenu($datatabs,"import",$innermenu);
%end:%
%insert:before%
###Gedcom Import Purge Location 3: Insert an Inner Mod Menu
if (file_exists('rrinnermodmenu_lib.php')) {
include_once('rrinnermodmenu_lib.php');
$innermenu .= rrimmBuildInnerModMenu('Gedcom Import Purge', 1, 'importconfig', '', "https://tng.lythgoes.net/wiki/index.php?title=Gedcom_Import_Purge#Details");
}
###Gedcom Import Purge Location 3: End of insertion
%end:%
******* admin_dataimport.php Location 4 - New checkboxes offering to purge Gedcom-imported links & suppress Citation Medialinks
%location:%
<div><input type="checkbox" name="importlatlong" value="1"> <?php echo $admtext['importlatlong']; ?></div>
%end:%
%insert:before%
<?php
###Gedcom Import Purge Location 4: Add two checkboxes
#The "Purge media links..." checkbox is displayed only if the createdfromgedcom field exists
#Check for the new database field. Set a variable that will be used in the medialinks SQL query
$query = "SHOW columns FROM $medialinks_table WHERE field = 'createdfromgedcom'";
$result = tng_query($query);
if (tng_num_rows($result) == 1) {
#The field label is immediately followed by a help link.
$checked = $rrconfig['GedcomPurgeMedialinks'] ? ' checked' : '';
echo "<div><label><input type='checkbox' id='rrPurgeMedialinks' name='rrPurgeMedialinks'
value='1'$checked>{$admtext['rrgip-purgelinks']}
<a href='#' title='Help page'
onclick=\"openHelp('languages/English/data_help.php#rrpurgemod');
return false;\"><img src='img/info_2.png' width='16' height='16'/></a>
</label></div>\n";
} else {
echo "<div style='font-weight:bold;color:brown;'>{$admtext['rrgip-nofield1']}<br>
{$admtext['rrgip-nofield2']} <a href='rrgedcomimportpurge_dbsetup.php?return=import'>{$admtext['rrgip-nofield3']}</a>{$admtext['rrgip-nofield4']}
</div>
<input type='hidden' name='rrPurgeMedialinks' value=''>\n";
}
tng_free_result($result);
#2. Suppress citation medialinks
#The field label is immediately followed by a help link.
$checked = $rrconfig['GedcomPurgeNotCitations'] ? ' checked' : '';
echo "<div><label><input type='checkbox' name='notcitationlinks'
value='1'$checked>{$admtext['rrgip-nocitations']}
<a href='#' title='Help page'
onclick=\"openHelp('languages/English/data_help.php#rrCitationMedialinks');
return false;\"><img src='img/info_2.png' width='16' height='16'/></a>
</label></div>\n";
###Gedcom Import Purge Location 4: End of insertion
?>
%end:%
*************** admin_dataimport.php Location 5 - List mods that affect this program
%location:%
</table>
</form>
%end:%
%insert:after%
<?php ###Gedcom Import Purge Location 5 Show Mods
if (file_exists('rrshowmodnames_include.php')) include_once ('rrshowmodnames_include.php');
?>
%end:%
***********************************************************************
*************************************************************
%target:admin_gedimport.php%
*** The main program for the Gedcom Import process
%location:%
include("begin.php");
%end:%
%insert:after%
##### admin_gedimport.php, modified by ###Gedcom Import Purge, by Robin Richmond
# The functional changes are in subroutine libraries.
# The "main" program in this file is modified only to set a flag to say whether createdfromgedcom field is missing,
# and to invoke the ShowModName code.
# Note that this page might appear as a progress monitor popped up over the admin_dataimport.php form.
# Messages generated by this mod are just for the full page, not for the popup.
$tngModNames['Gedcom Import Purge']['admin_gedimport.php'] = '5e'; #Register this mod
########################################################
#Read custom language strings from a mods subfolder rather than from standard TNG custom text files.
$modfolder = 'gedcom_import_purge_v13.0.0.5e';
include("$modspath/$modfolder/languages/English_custtext.php");
if ($mylanguage != "languages/English" && file_exists("$modspath/$modfolder/{$mylanguage}_custtext.php"))
include("$modspath/$modfolder/{$mylanguage}_custtext.php");
#########################################################
#Check for the new database field. Set a variable that will be used in the medialinks SQL query
$query = "SHOW columns FROM $medialinks_table WHERE field = 'createdfromgedcom'";
$result = tng_query($query);
$rrFromGedcomFieldMissing = (tng_num_rows($result) != 1);
tng_free_result($result);
########################################################
%end:%
*************** admin_gedimport.php Location 2 - Show mods at the bottom of the page
%location:%
echo tng_adminfooter();
%end:%
%insert:before%
###Gedcom Import Purge Location 2: Show Mod Names
if (file_exists('rrshowmodnames_include.php')) include_once ('rrshowmodnames_include.php');
%end:%
***********************************************************************
***********************************************************************
%target:gedimport_misc.php%
*** One of several function libraries used by the gedcom import ***
*** We'll change it to set the createdfromgedcom flag in Medialinks
%location:%
//set trim_it to a non-zero value to use this feature
%end:%
%insert:before%
##### gedimport_misc.php, modified by ###Gedcom Import Purge, by Robin Richmond
# In the processMedia function, the new 'createdfromgedcom' field is set to 1 for each Medialink
# that the Gedcom Import process creates. (Medialinks.createdfromgedcom was created by this mod.)
$tngModNames['Gedcom Import Purge']['gedimport_misc.php'] = '5e'; #Register this mod
#############################################################################
%end:%
******* gedimport_misc.php Location 2 - In function saveCitation, conditionally suppress citation medialinks
*** code fragment insertion with inline PHP comment
*** $notcitationlinks is a querystring parameter generated by the kickoff form.
%location:%
is_array($cite['MEDIA'])
%end:%
%triminsert:after%
&& (!isset($GLOBALS['notcitationlinks']) || !$GLOBALS['notcitationlinks'])/*###Gedcom Import Purge Locations 2: Conditionally suppress citation medialinks*/
%end:%
******* gedimport_misc.php Location 2b
%location:%
//insert ignore or update medialink
%end:%
%insert:after%
###Gedcom Import Purge Location 2b: The changes to the SQL query depend on whether the createdfromgedcom field exists
if ($GLOBALS['rrFromGedcomFieldMissing']) {
$rrInsertField = $rrInsertValue = $rrUpdateAssign = '';
} else {
$rrInsertField = ", createdfromgedcom";
$rrInsertValue = ", 1";
$rrUpdateAssign = ", createdfromgedcom=1";
}
###Gedcom Import Purge Location 2b: End of insertion
%end:%
******* gedimport_misc.php Location 3 - Add the new createdfromgedcom field to the Medialinks INSERT statement
*** code fragment, without comment, on the same line as the next location***
%location:%
eventID, defphoto
%end:%
%triminsert:after%
$rrInsertField
%end:%
******* gedimport_misc.php Location 4 - Add the createdfromgedcom value to the Medialinks INSERT statement
*** code fragment, on the same line as the previous location. ***
%location:%
{$mm['defphoto']}\"
%end:%
%triminsert:after%
$rrInsertValue /*###Gedcom Import Purge Locations 3&4: Add createdfromgedcom fieldname & value*/
%end:%
******* gedimport_misc.php Location 5 - Add the createdfromgedcom field & value to a Medialinks UPDATE statement
*** code fragment with inline SQL comment ***
%location:%
{$mm['NOTE']}\"$defphotostr
%end:%
%triminsert:after%
$rrUpdateAssign /* ###Gedcom Import Purge Location 5: Add createdfromgedcom field */
%end:%
***********************************************************************
***********************************************************************
%target:gedimport_trees.php%
*** One of several function libraries used by the Gedcom import ***
%location:%
function ClearData( $tree ) {
%end:%
%insert:before%
##### gedimport_trees.php, modified by ###Gedcom Import Purge, by Robin Richmond
# function ClearData now
# - Deletes only those Medialinks that are flagged as being created by a Gedcom import
# - Does not delete places with a geoignore, placelevel, or zoom value. */
#############################################################################
%end:%
******* gedimport_trees.php Location 2 - Purge places and medialinks in the ClearData function
%location:%
$query = "DELETE from $places_table WHERE gedcom = \"$tree\" AND (latitude is null OR latitude = \"\") AND (longitude is null OR longitude = \"\") AND (notes is null OR notes = \"\")";
$result = tng_query($query);
%end:%
%replace:%
###Gedcom Import Purge location 2 - Purge places and medialinks
global $old, $media_table, $tngconfig, $admtext;
global $rrPurgeMedialinks; #A new form field value passed from the Gedcom Import kickoff form
$GLOBALS['tngModNames']['Gedcom Import Purge']['gedimport_trees.php(ClearData)'] = '5e'; #Register the mod
#Don't purge places if there is more than one tree but only one places list, since
#purging places without regard to their use in other trees can break external reference
#from records in those trees.
if ($tngconfig['places1tree'] && $tree_cnt>1) {
$rrpurged = 0;
} else { #Purge places that do not have certain attributes, and that do not have medialinks.
if ($tngconfig['places1tree']) {
$rrSQLwhere = $rrSQLjoin = "";
} else {
$rrSQLjoin = " AND mm.gedcom = pp.gedcom";
$rrSQLwhere = " AND pp.gedcom = \"$tree\"";
}
$query = "DELETE pp FROM $places_table pp
LEFT JOIN $medialinks_table mm ON mm.personID = pp.place $rrSQLjoin
WHERE (latitude is null OR latitude = '') AND (longitude is null OR longitude = '')
AND (notes is null OR notes = '')
AND (zoom is null OR zoom=0) AND (placelevel is null or placelevel=0)
AND geoignore=0
AND mm.medialinkID is null $rrSQLwhere";
$result = tng_query($query);
$rrpurged = tng_affected_rows();
}
if ($old) {
echo "<div>{$admtext['rrgip-intree']}: $tree</div>";
echo "<div>" . str_replace("##", $rrpurged, $admtext['rrgip-purgedplaces']) . "</div>\n";
}
#Purge media links created by a Gedcom Import. Make sure that the createdfromgedcom field exists.
$query = "SHOW columns FROM $medialinks_table WHERE field = 'createdfromgedcom'";
$result = tng_query($query);
$rrFieldIsPresent = (tng_num_rows($result) == 1);
tng_free_result($result);
if ($rrPurgeMedialinks && rrFieldIsPresent) {
#Check for any value>0 so other processes can flag condition that are meaningful to them.
$query = "DELETE FROM $medialinks_table
WHERE gedcom = '$tree' AND createdfromgedcom>0";
$result = tng_query($query);
#Report how many medialinks were deleted and how many remain in this tree
if ($old){
echo "<div>" . str_replace("##",tng_affected_rows(),$admtext['rrgip-purgedlinks']) . "</div>\n";
$query = "SELECT count(medialinkID) as linkcount from $medialinks_table WHERE gedcom = '$tree'";
$result = tng_query($query);
$rrRow = tng_fetch_assoc( $result );
echo "<div>" . str_replace("##", $rrRow['linkcount'], $admtext['rrgip-linksnow']) . "</div>\n";
}
} #end if purge links
###Gedcom Import Purge Location 2 - End of replacement text
%end:%
***********************************************************************
**************************************************************************
%target:languages/English/data_help.php%
*** The help file for Gedcom import and export ***
%location:%
include("../../helplib.php");
%end:%
%insert:before%
##### admin_dataimport.php, modified by ###Gedcom Import Purge, by Robin Richmond
# A new section describes features implemented by this mod, and the form field that controls those features.
$tngModNames['Gedcom Import Purge']['data_help.php'] = '5e';
#############################################################################
%end:%
******* data_help.php Location 2 - A new section for this mod
%location:%
<a name="export"><p class="subheadbold">GEDCOM Export</p></a>
%end:%
%insert:before%
<!-- ###Gedcom Import Purge Location 2: New Section about the mod -->
<div style='border:1px solid blue; padding:8px;'>
<h2 id="rrpurgemod" style='color:blue;'>Changes made by the Gedcom Import Purge mod</h2>
<h4 style="margin-bottom:0;">1. Purging Place Records</h4>
The Gedcom Import Purge changes the Gedcom Import process to limit the number of places that are purged.
As the import starts, it no longer purges
<ul><li>Any Places on sites where there are multiple trees, and just one Place list
(since such places might be used by trees other than the one being imported),</li>
<li>Places with a placelevel value (since placelevels cannot be obtained from a Gedcom file), or</li>
<li>Places with a Medialink (since Place medialinks can only be created from within TNG, not through Gedcom import).</li>
</ul></li>
</ol>
<h4 style="margin-bottom:0;">2. Purging Medialinks</h4>
The native Gedcom Import Process purges all Person, Family, Source, Repository, Citation, and Event data from the tree being loaded,
because all such data is expected to be supplied by the Gedcom file.
There is simply no decent way to mix Gedcom import of these record types with TNG data entry
(at least when you are importing an entire tree.)
<p>But media information is different.
It is very common for TNG administrators to import some media items and medialinks from Gedcom files,
and to do manual uploading and data entry of some media items, their descriptions, and their links to other database objects.
Since TNG does not natively provide a way to distinuish media items and medialinks
that are created through Gedcom Imports from those that are created through TNG data entry,
all a native TNG Gedcom import can do is to leave <b>all</b> media items and medialinks intact,
causing Medialinks records that have been removed from the source database to remain in TNG after the import.
</p>
<p style='margin-bottom:0;';>The Gedcom Import Purge mod addresses this problem by</p>
<ol style='margin-top:0;'>
<li>Installing a one-time setup program that creates a new database field in the Medialinks table
that indicates whether a medialink was created during a Gedcom import
or was defined "manually" - through TNG data entry programs.
The new field is named "createdfromgedcom", and it is set to 1 for medialinks created
during a Gedcom Import.</li>
<li>Purging (at the beginning of a Gedcom Import) all medialinks that are flagged
as being created by a Gedcom Import
(but doing so only if the user checks the mods "Purge Medialinks" checkbox in the Gedcom Import kickoff form.</li>
<li>Adding a form field in the Medialinks section of the Edit Media form so that
users can view each medialink's "createdfromgedcom" flag.
(The form allows the user to set or reset that flag, but the flag really represents
how the medialink was created, so it would be fairly unusual to change its setting.)</li>
</ol>
<h4 style="margin-bottom:0;" id='rrCitationMedialinks'>3. The Gedcom Import Purge mod and Citation Medialinks</h4>
For a period of time between incremental versions of TNGv12, the Gedcom Import would invalidate
all existing Citation Medialinks and leave in place, and the invalid Medialinks would sometimes
show up TNG pages such as Person Profiles.
To respond to this problem, the Gedcom Import Purge mod added a "Suppress the creation of citation medialinks"
button on the Gedcom Import kickoff form, and changed the Gedcom Import process to act on that button.
<p>This problem has been resolved, so, really, there is virtually no reason to have the
"Suppress the creation of citation medialinks" checkbox any more.
About the only thing it accomplishes is to suppress linked media item thumbnails on source citations in the Person Profile.
</p>
See <a href='https://tng.lythgoes.net/wiki/index.php?title=Gedcom_Import_Purge#CitationMedialinks'>the Gedcom Import Purge Wiki article</a> for more information.</p>
</div>
</td>
</tr>
<tr class="databack">
<td class="tngshadow">
<p style="float:right"><a href="#top">Top</a></p>
<!-- ### Gedcom Import Purge Location 2: End of insertion -->
%end:%
******* data_help.php Location 3 - Show mod names.
%location:%
</body>
%end:%
%insert:before%
<?php
###Gedcom Import Purge Location 3: Show mod names
if (file_exists('rrshowmodnames_include.php')) include_once ('rrshowmodnames_include.php');
?>
%end:%
***********************************************************************
***********************************************************************
%target:admin_editmedia.php%
*** - The MediaLinks table is in a subform that generated by micro_medialinks.php.
*** - The "Purge on Gedcom" checkbox (like "Show" and others) is an "immediate action" field; that is,
*** the database field is updated as soon as the checkbox is checked or unchecked.
*** - mediafind.js and mediautils.js, get and save the checkbox values.
%location:%
include("begin.php")
%end:%
%insert:after%
##### admin_editmedia.php, modified by ###Gedcom Import Purge, by Robin Richmond
# Adds a checkbox in the MediaLinks subform for the "Purge on Gedcom Import" field.
# Most of the work to add the checkbox is done in micro_medialinks.php and to two
# Javascript files, mediautils.js and mediafind.js.
$tngModNames['Gedcom Import Purge']['admin_editmedia.php'] = '5e';
########################################################
#Read custom language strings from a mods subfolder rather than from standard TNG custom text files.
$modfolder = 'gedcom_import_purge_v13.0.0.5e';
include("$modspath/$modfolder/languages/English_custtext.php");
if ($mylanguage != "languages/English" && file_exists("$modspath/$modfolder/{$mylanguage}_custtext.php"))
include("$modspath/$modfolder/{$mylanguage}_custtext.php");
########################################################
#Check for the new database field. Set a variable that will be used in the medialinks SQL query
$query = "SHOW columns FROM $medialinks_table WHERE field = 'createdfromgedcom'";
$result = tng_query($query);
if (tng_num_rows($result) == 1) {
$rrQueryField = "createdfromgedcom";
$rrFromGedcomFieldMissing = false;
} else {
$rrQueryField = "0 AS createdfromgedcom";
$rrFromGedcomFieldMissing = true;
}
tng_free_result($result);
########################################################
%end:%
******* admin_editmedia.php Location 2 - Add the new Gedcom Purge database field to the SQL query
*** Code fragment insertion. The search string is at the very end of a line of SQL code,
*** and ends with the last field in the SELECT list. The insertion adds a comma to the
*** end of the existing line, add adds a new line with a new fieldname and an SQL comment.
*** The variable rrQueryField causes all medialinks to appear to have createdfromgedcom=0
*** if the createdfromgedcom field does not exist.
%location:%
$families_table.private as fprivate
%end:%
%triminsert:after%
,
$rrQueryField /* ###Gedcom Import Purge Location 2: Add the new createdfromgedcom field to the query */
%end:%
******* admin_editmedia.php Location 3 - Show mod names
%location:%
</td>
</tr>
</table>
</form>
%end:%
%insert:after%
<?php
### Gedcom Import Purge Location 3: Show Mod Names
if (file_exists('rrshowmodnames_include.php')) include_once ('rrshowmodnames_include.php');
?>
%end:%
***********************************************************************
***********************************************************************
%target:js/mediafind.js%
*** When a new medialink is created, a new row is inserted into the medialinks data table, in the
*** medialinks subform of the Cemetery Edit page.
*** The code inserted into this file inserts a cell for the "From Gedcom" column, but does not
*** populate that table cell. It is populated by mediautils.js.
%location:%
function getPotentialLinks(linktype) {
%end:%
%insert:before%
/*##### mediafind.js, modified by ###Gedcom Import Purge, by Robin Richmond*/
/* Insert a data cell for the "From Gedcom" column into the new medialinks table row created for a new medialink.
$tngModNames['Gedcom Import Purge']['mediafind.js'] = '5e'; (just a comment)
############################################################################# */
%end:%
**********************js/mediafind.js Location 2: Add an HTML table cell cell for the Purge on Gedcom Field
%location:%
td7.setAttribute('align','center');
%end:%
%insert:after%
//###Gedcom Import Purge Location 2: Add an HTML table cell cell for the createdfromgedcom field,
//so the user can set or unset the checkbox
if (!rrFromGedcomFieldMissing) {
var td8 = insertCell(newtr,8,"lightback normal",'<input type="checkbox" name="gedcom'+linkID+'" id="gedcom'+linkID+'" onclick="toggleGedcom(this);" value="1""/>');
td8.id = 'gedcom'+linkID;
td8.setAttribute('align','center');
}
//###Gedcom Import Purge Location 2: End of insertion
%end:%
***********************************************************************
***********************************************************************
%target:js/mediautils.js%
*** The new funtion function toggleGedcom invokes the misnamed AJAX file ajx_updateorder.php which
*** places the new CreatedFromGedcom checkbox that is in the medialinks subform of the Media Edit page.
*** Each field in the medialinks subform is saved to the database the moment it is changed.
*** (That is, there is an onchange or onclick event for each field that triggers an Ajax
*** call that saves only one field to one record.)
*** The database field medialinks.createdfromgedcom is created by this mod. It is a tinyint field that
*** is set to 1 by the Gedcom Import process whenever a Gedcom Import saves a medialink record.
*** (Other processes can set it to other positive integers to flag special cases.)
%location:%
var gsControlName = "";
%end:%
%insert:before%
/*##### mediautils.js, modified by ###Gedcom Import Purge, by Robin Richmond*/
/* The new funtion function toggleGedcom invokes the AJAX file ajx_updateorder.php to populate a new
table cell for the new createdfromgedcom field.
$tngModNames['Gedcom Import Purge']['mediautils.js'] = '5e'; (just a comment)
############################################################################# */
%end:%
**********************js/mediautils.js Location 2 - New Javascript function
%location:%
function toggleShow(checkbox) {
%end:%
%insert:before%
//###Gedcom Import Purge Location 2: New Function to invoke Ajax to save the createdbygedcom flag from a medialinks record
//////////////////////////////////////////////////////////////////////////////////////
//Each checkbox in the medialinks subform of the Media Edit form has its own function, whose name matches the
//fieldname and elementID prefix of the corresponding data field. The functions for each field are virutually
//identical - in fact, the only real differences among them are the base fieldname & values, and the fact that
//one of the fields has a negative value (that is, when the checkbox is checked, the database value should be zero.
//Each function grabs the medialinkID from the checkbox's fieldname, and passes the medialinkID, the checkbox
//status, and the base fieldname (as an 'action' value) to the multi-purpose Ajax program ajx_updateorder.php.
function toggleGedcom(checkbox) {
var toggle = checkbox.checked ? 1 : 0;
var medialinkID = checkbox.name.substr(6); //Strip 'gedcom' from the front of the fieldname
var params = {medialinkID:medialinkID, toggle:toggle, action:'gedcom'};
jQuery.ajax({
url: cmstngpath + 'ajx_updateorder.php',
data: params
});
} //end function toggleGedcom
//###Gedcom Import Purge Location 2: End of insertion
%end:%
***********************************************************************
***********************************************************************
%target:micro_medialinks.php%
%location:%
$linkrows = "";
%end:%
%insert:before%
##### micro_medialinks.php, modified by ###Gedcom Import Purge, by Robin Richmond
# Adds a "Purge on Gedcom" checkbox column to the HTML layout table for the MediaLinks form.
$tngModNames['Gedcom Import Purge']['micro_medialinks.php'] = '5e';
###################################################################
%end:%
************************ micro_medialinks.php Location 2 - Add a table cell with a checkbox for the 'Created by Gedcom' field
*** Multi-line code fragment replacement with HTML comment.
*** The search string is at the end of a line of PHP code, and represented the end of a <td> element plus
*** the </tr> tag (within a PHP string).
*** The replacement string replaces the code fragment for the <td> element (which was only in the search
*** string to define a unique string), adds code for a new <td> element, and generates the </tr> tag.
*** As usual, the replacement string ends with a comment.
%location:%
value=\"1\"$schecked\"/></td></tr>\n";
%end:%
%trimreplace:%
value=\"1\"$schecked\"/></td>";
###Gedcom Import Purge Location 2: For existing medialinks add a data table cell with a checkbox for the 'createdfromgedcom' field
###(this is a multiline code fragment insertion)
if (!$rrFromGedcomFieldMissing) {
$rrchecked = $plink['createdfromgedcom']>0 ? " checked" : "";
$linkrows .= "<td class=\"lightback normal\" align=\"center\" id=\"gedcom_{$plink['mlinkID']}\"><input type=\"checkbox\" name=\"gedcom{$plink['mlinkID']}\" id=\"gedcom{$plink['mlinkID']}\" onclick=\"toggleGedcom(this);\" value=\"1\"$rrchecked/></td></tr>\n";
}
###Gedcom Import Purge Location 2: End of insertion
%end:%
************************ micro_medialinks.php Location 3:
%location:%
tng_free_result($result2);
}
%end:%
%insert:after%
###Gedcom Import Purge Location 3: Warning message if the From Gedcom field is missing
if ($rrFromGedcomFieldMissing)
echo "<div style='font-weight:bold;color:brown;'>{$admtext['rrgip-nofield1']}<br>
{$admtext['rrgip-nofield2']} <a href='rrgedcomimportpurge_dbsetup.php?return=media'>{$admtext['rrgip-nofield3']}</a>{$admtext['rrgip-nofield4']}
</div>\n";
##Also generate inline Javascript to save the missing field flag in a global Javascript variable
echo "<script>rrFromGedcomFieldMissing = $rrFromGedcomFieldMissing;</script>\n";
###Gedcom Import Purge Location 3: End of insertion
%end:%
************************ micro_medialinks.php Location 4: Add the Created by Gedcom column heading to the MediaLinks form -->
%location:%
<td class="fieldnameback fieldname nw"> <b><?php echo $admtext['show']; ?></b> </td>
%end:%
%insert:after%
<?php
###Gedcom Import Purge Location 4: Add the From Gedcom column heading to the MediaLinks form
if (!$rrFromGedcomFieldMissing)
echo "<td class='fieldnameback fieldname'>{$admtext['rrgip-fromgedcom']}</td>\n";
###Gedcom Import Purge Location 4: End of insertion
?>
%end:%
***********************************************************************
***********************************************************************
%target:ajx_updateorder.php%
%location:%
include("begin.php");
%end:%
%insert:before%
##### ajx_updateorder.php, modified by ###Gedcom Import Purge, by Robin Richmond
#Adds an Action to update the Gedcom flag in the medialinks table "Purge on Gedcom" checkbox
#column to the HTML layout table for the MediaLinks form.
$tngModNames['Gedcom Import Purge']['ajx_updateorder.php'] = '5e';
#############################################################################
%end:%
******************* ajx_updateorder.php Location 2
%location:%
case "show":
%end:%
%insert:before%
###Gedcom Import Purge Location 2: New Action to update the Gedcom flag in the medialinks table
case "gedcom":
$query = "UPDATE $medialinks_table SET createdfromgedcom = $toggle WHERE medialinkID=\"$medialinkID\"";
$result = @tng_query($query);
$rval = $query . $result;
break;
###Gedcom Import Purge Location 2: End of insertion
%end:%
**********************************************************************
**********************************************************************
%target:admin_importconfig.php%
*** The Admin >> Settings >> Import Settings form
%location:%
include("begin.php");
%end:%
%insert:before%
$tngModNames['Gedcom Import Purge']['admin_importconfig.php'] = '5e'; #Three checkboxes
%end:%
*************** admin_importconfig.php Location 2 - The mod options
%location:%
</td>
</tr>
</table>
%end:%
%insert:after%
<?php ###############################################################
###Gedcom Import Purge Location 2: Three checkboxes that affect for the Gedcom Import kickoff form
include_once('rrmodsettingsblocks.php'); #Handle the mod options
########################################################
#Read custom language strings from a mods subfolder rather than from standard TNG custom text files.
$modfolder = 'gedcom_import_purge_v13.0.0.5e';
include("$modspath/$modfolder/languages/English_custtext.php");
if ($mylanguage != "languages/English" && file_exists("$modspath/$modfolder/{$mylanguage}_custtext.php"))
include("$modspath/$modfolder/{$mylanguage}_custtext.php");
if (!isset($rrconfig['GedcomPurgeImportMedia'])) $rrconfig['GedcomPurgeImportMedia'] = '1';
if (!isset($rrconfig['GedcomPurgeMedialinks'])) $rrconfig['GedcomPurgeMedialinks'] = '1';
if (!isset($rrconfig['GedcomPurgeNotCitations'])) $rrconfig['GedcomPurgeNotCitations'] = '0';
echo "<table class='rrmsbConfigTable' modname='Gedcom Import Purge' group='Gedcom'>
<tbody>
<input type='hidden' name='rrconfig[Gedcom Import Purge]'
value='GedcomPurgeImportMedia, GedcomPurgeMedialinks, GedcomPurgeNotCitations'>\n";
#An introductory note
echo "<tr><td>{$admtext['rrgip-optionsnote']}</td>
<td></td></tr>\n";
#The 'Import media if present' checkbox
$checked = ($rrconfig['GedcomPurgeImportMedia']) ? ' checked' : '';
echo "<tr><td><label for='rrconfig[GedcomPurgeImportMedia]'>{$admtext['rrgip-importoption']}</label></td>
<td><input type='checkbox' name='rrconfig[GedcomPurgeImportMedia]' value='1'$checked>
</td></tr>\n";
#The 'Purge media links created by previous Gedcom imports' checkbox
$checked = ($rrconfig['GedcomPurgeMedialinks']) ? ' checked' : '';
echo "<tr><td><label for='rrconfig[GedcomPurgeMedialinks]'>{$admtext['rrgip-purgelinks']}</td>
<td><input type='checkbox' name='rrconfig[GedcomPurgeMedialinks]' value='1'$checked>
</td></tr>\n";
#The 'Suppress Citation Medialinks' checkbox
$checked = ($rrconfig['GedcomPurgeNotCitations']) ? ' checked' : '';
echo "<tr><td><label for='rrconfig[GedcomPurgeNotCitations]'>{$admtext['rrgip-nocitations']}</td>
<td><input type='checkbox' name='rrconfig[GedcomPurgeNotCitations]' value='1'$checked>
</td></tr>\n";
echo "</tbody>
</table>\n";
# Use a Javascript document.ready function to remove a footnote that sits below the
# form's Save button (and below the mod settings blocks for all Gedcom Import mods)
# and insert it in the form right below the fields that it refers to.
# This code is replicated exactly in the Gedcom Import Purge, Gedcom Import Monitor,
# and Gedcom Import Mediatype mods.
?>
<script>
$(function() {
var footnote = $("p:contains('<?php echo $admtext['commas']; ?>')");
if (footnote.length) {
footnote.remove();
var html = "<tr><td colspan='2'>* <?php echo $admtext['commas']; ?></td></tr>";
var td = $("form tr:contains('<?php echo $admtext['nopathmatch']; ?>')").before(html);
}
});
//////////////////////////////////////////////////
//function rrgipOpenWikiPage opens a TNG Wiki page as a popup.
//It is invoked (at least) by the blue information icon next to the new "Suppress Citation Medialinks" checkbox.
function rrgipOpenWikiPage(article, anchor='') {
newwindow = window.open('https://tng.lythgoes.net/wiki/index.php?title='+article+'#'+anchor, 'wikiwindow', 'height=600, width=780, top=50, left=100, resizable=yes, scrollbars=yes, status=yes');
newwindow.focus();
return false;
} //end function rrmsbOpenWikiPage
</script>
<?php
if (file_exists('rrshowmodnames_include.php')) include_once ('rrshowmodnames_include.php');
###Gedcom Import Purge Location 2: End of Insertion
?>
%end:%
*************************************************************************
*************************************************************************
%target:admin_updateimportconfig.php%
*** Saves the Import/Export Configuration Settings to the file importconfig.php
%location:%
include("begin.php");
%end:%
%insert:before%
$tngModNames['###Gedcom Import Purge']['admin_updateimportconfig.php'] = '5e';
######################################################################
%end:%
*************** admin_updateimportconfig.php Location 2 - Save any new settings for this mod
*** I'm not crazy about using this search text, but Darrin changed fwrite( $fp, "?>\n" ); in TNGv13
*** to fwrite( $fp, "?>" );
*** (without \n) in TNGv13.0.1, and at least this line is consistent between the two versions.
%location:%
fwrite( $fp, "\$tngimpcfg['coerce'] = \"$coerce\";\n" );
%end:%
%insert:after%
###Gedcom Import Purge Location 2: Use a field to find the fields to save
foreach (array_map('trim', explode(',', $rrconfig['Gedcom Import Purge'])) as $param)
fwrite( $fp, "\$rrconfig['$param'] = '{$rrconfig[$param]}';\n" );
###Gedcom Import Purge Location 2: End of Insertion
%end:%
**********************************************************************
**********************************************************************
%target:files%
%newfile:rrgedcomimportpurge_dbsetup.php%
%fileversion:v13.0.0.5e%
<?php
##### gedcom_import_purge_dbsetup.php, modified by ###Gedcom Import Purge, by Robin Richmond
// %version:v13.0.0.5e%
# Creates or deletes a flag field in the Medialinks table that marks medialinks
# created by the Gedcom import process rather than the TNG editor(s).
# Installed by the Gedcom Import-Purge mod.
# Must be run after the mod is installed but before the next Gedcom Import.
# If the field exists, the program will note that, and invoke itself with a querystring
# parameter whose value in English is "Delete It".
# If the field does not exist, the program will note that, and invoke itself with a
# querystring parameter whose value in English is "Create It".
#
# v5e - 29 Oct 2020
# Added error checking, and moved the file into the .cfg file
# v12 - Jun 2016
# In order to avoid a weird PHP/TNG conflict that causes Admin programs
# running outside of the standard TNG folder to reset the user session,
# this program was
# - modified to run in the standard TNG folder, and
# - renamed so that its origins are clear.
$tngModNames['Gedcom Import-Purge']['gedcom_import_purge_dbsetup.php'] = '5e'; #Register this mod
include("begin.php");
include($cms['tngpath'] ."adminlib.php");
$textpart = "textplus";
include($cms['tngpath'] ."getlang.php");
include($cms['tngpath'] ."$mylanguage/admintext.php");
$admin_login = 1;
include($cms['tngpath'] ."checklogin.php");
include($cms['tngpath'] ."version.php");
require($cms['tngpath'] ."adminlog.php");
########################################################
#Read custom language strings from a mods subfolder rather than from standard TNG custom text files.
$modfolder = 'gedcom_import_purge_v13.0.0.5e';
include("$modspath/$modfolder/languages/English_custtext.php");
if ($mylanguage != "languages/English" && file_exists("$modspath/$modfolder/{$mylanguage}_custtext.php"))
include("$modspath/$modfolder/{$mylanguage}_custtext.php");
########################################################
$flags['tabs'] = $tngconfig['tabs'];
tng_adminheader( $admtext['rrgip-heading1'], $flags );
echo "</head>\n";
echo tng_adminlayout();
$purgetabs[0] = array(1,"rrgedcomimportpurge_dbsetup.php", $admtext['rrgip-tab0'],"setup");
$innermenu = "<a href=\"#\" onclick='window.close();' class=\"lightlink\">{$admtext['rrgip-returntomm']}</a>";
$menu = doMenu($purgetabs,"setup",$innermenu);
echo displayHeadline($admtext['rrgip-heading1'] , "{$cms['tngpath']}img/photos_icon.gif",$menu,$message);
?>
<table width="100%" border="0" cellpadding="10" cellspacing="2" class="lightback">
<tr class="databack">
<td class="tngshadow normal">
<span class="subhead"><strong><?php echo $admtext['rrgip-heading2']; ?></strong></span><br/><br/>
<?php
$fieldname = "createdfromgedcom";
//Before displaying the form, take any action that was specified by button b1
if ($b1 == $admtext['rrgip-create']){
//Double-check that it does not exist
$query = "SHOW columns FROM $medialinks_table WHERE field = \"$fieldname\"";
$result = tng_query($query);
if (tng_num_rows($result) == 0) {
//Create the field
$query = "ALTER TABLE $medialinks_table ADD $fieldname TINYINT NOT NULL DEFAULT '0' COMMENT 'Created by the Gedcom Import Purge mod'";
echo "<div>SQL Command: $query </div>\n";
$result = @tng_query($query);
if( $result )
echo "...{$admtext['rrgip-done']}\n";
else
echo "...<strong>{$admtext['rrgip-notcreated']}</strong>\n";
} else {
echo "<p><strong>{$admtext['rrgip-alreadyexists']}</strong></p>\n";
}
} elseif ($b1 == $admtext['rrgip-delete']) {
//Double-check that it still exists
$query = "SHOW columns FROM $medialinks_table WHERE field = \"$fieldname\"";
$result = tng_query($query);
if (tng_num_rows($result) == 1) {
//Delete the field.
$query = "ALTER TABLE $medialinks_table DROP $fieldname";
echo "<div>SQL Command: $query </div>\n";
$result = @tng_query($query);
if( $result ) echo "...{$admtext['rrgip-done']}\n";
else echo "...<strong>{$admtext['rrgip-notdeleted']}</strong>\n";
} else {
echo "<p><strong>{$admtext['rrgip-alreadygone']}</strong></p>\n";
}
}
############# End of actions ############
#Check for the field and display the appropriate action button
$query = "SHOW columns FROM $medialinks_table WHERE field = \"$fieldname\"";
$result = tng_query($query);
$fieldIsPresent = (tng_num_rows($result) == 1);
tng_free_result($result);
echo "<form>\n";
echo "<p style='font-size:115%; font-weight:bold;'>";
if ($fieldIsPresent) {
echo "{$admtext['rrgip-exists']} 
<input type=\"submit\" name=\"b1\" value=\"{$admtext['rrgip-delete']}\" />";
}
else {
echo "{$admtext['rrgip-notexist']} 
<input type=\"submit\" name=\"b1\" value=\"{$admtext['rrgip-create']}\" />";
}
echo "</p></form>
<p style='font-weight:bold;'>{$admtext['rrgip-close']}</p>
";
?>
</td>
</tr>
</table>
<?php
echo tng_adminfooter();
?>
%fileend:%
**********************************************************************************
*** The language strings are in the 'languages' folder in the standard mod subfolder.