0001: 
This is a TNG mod directive file
0002: 
%name:Gedcom Import Purge%
0003: 
%version:13.0.0.5e%
0004: 
%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.
0005: 
<p>The two optional actions are controlled by checkboxes on the Gedcom Import kickoff form.</p>
0006: 
<p style='border:2px solid black;padding-left:6px;' class='databack'>To keep track of imported Medialinks,
0007: 
this mod requires a new database field in the Medialinks table. <i>After the very first time</i> that you install the mod,
0008: 
<a href="rrgedcomimportpurge_dbsetup.php?return=mm" target="_blank">create the database field</a>,
0009: 
which is called <i>createdfromgedcom</i>.<br>
0010: 
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>
0011: 
<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>,
0012: 
and old medialinks will therefore not be purged, even if the checkbox that says to purge old medialinks is checked. 
0013: 
%
0014: 
%wikipage:Gedcom_Import_Purge%
0015: 
%author:Robin Richmond:https://tng.lythgoes.net/wiki/index.php?title=User:Robinrichm%
0016: 
0017: 
**********************************
0018: 
*** Revision History ***
0019: 
v13.0.0.5e 02 Nov 2020
0020: 
* Had to change a target Location to accommodate a underlying change (whose purpose I don't understand) in TNGv13.0.1
0021: 
v13.0.0.5d 28 Oct 2020
0022: 
* Fixed a bug that prevented the database utility from deleting the new database field.
0023: 
* Handled the missing FromGedcom field error in the Gedcom Import process and in Edit Cemeteries.
0024: 
  This required changes to most of the target files.
0025: 
  - The Gedcom Import kickoff form and the Cemetery edit page both now have links to the
0026: 
    database setup program, and load it into the same browser tab.
0027: 
  - The three links to the database setup program (including from the .cfg file description) pass a "return"
0028: 
    parameter, and the setup program can be closed (to return to MM) only if it was invoked by MM.
0029: 
v13.0.0.5c 28 Oct 2020
0030: 
* Moved the utility that creates the database field into the .cfg file as %newfile to fix the reference to the language file. 
0031: 
v13.0.0.5b 27 Aug 2020
0032: 
* Changed the popup help text (in the Import/Export help file) for the Citation Medialinks option.
0033: 
* Fixed the missing language strings in the configuration file.
0034: 
v13.0.0.5a 8 Aug 2020
0035: 
* Changed the last admin_gedimport.php target location to handle the new function tng_adminfooter.
0036: 
* Upgraded to the TNGv13 version of the Inner Mod Menu mod.
0037: 
v5a 15 Jan 2019
0038: 
# Upgraded to version 4 of the shared mod libraries.
0039: 
# Don't purge places if there is more than one tree but only one places list, since
0040: 
  purging places without regard to their use in other trees can break external reference
0041: 
  from records in those trees.
0042: 
# The Inner Mod Menu links to the Wiki article rather than to the help file to describe what the mod does.
0043: 
# Added a document.ready function in admin_importconfig.php to move a footnote from the bottom
0044: 
  of the page to a position right below the text it refers to. The insertion of the Gedcom Import
0045: 
  mods made that footnote too far from where it needs to be.
0046: 
# Added a checkbox to the Gedcom Kickoff import form that can suppress the creation of citation medialinks.
0047: 
# Fixed two missing %end:% tags that break installation in TNGv12.3
0048: 
v5 1 Oct 18
0049: 
- Modifies the Place purge process so that it does not purge places on sites that have mulitple
0050: 
  trees and have one shared Places list. Purging places from a shared Places list can delete
0051: 
  places that are used by other trees.
0052: 
- Inserts an Inner Mod Menu
0053: 
- Moves the mod parameters to TNG system options in a Mod Settings Block
0054: 
- Modifes the Edit Media form to allow the user to set or unset the new "createdfromgedcom" flag.
0055: 
  o A new "Purge on Gedcom" checkbox is displayed for each MediaLink associated with the current Media item.
0056: 
  o The new checkbox is in the HTML Medialinks table, in a new column next to the "Show" checkbox and column
0057: 
    (where "Show" means "Always show this media item, even if it linked to a person that the current
0058: 
    user is not allowed to see")
0059: 
v4 7 Apr 2018 for TNGv12
0060: 
- No functional changes
0061: 
- Updated the search text for gedimport_misc.php location 5 to remove a variable that is no longer
0062: 
  needed in a global statement.
0063: 
- Updated the cust_text.php search strings and the author tag
0064: 
- Added a note tag referring to the database setup
0065: 
- Updated the author tag.
0066: 
v3p 07 Nov 2017
0067: 
- Removed the second line from the cust_text.php target location search string
0068: 
v3a 14 Jul 2017
0069: 
- The medialinks purge wasn't reporting the correct number of unpurged links. It always reported 1.
0070: 
- The places purge wasn't purging places with null placelevel or zoom values. It only looked for 0.
0071: 
v3 10 May 2017
0072: 
- Fixed and cleaned up $admtext variables
0073: 
- The DisplayModNames mod is now optional
0074: 
- The info button class has been pulled into an embedded stylesheet, eliminating
0075: 
  a dependency on the Blue Info Button mod
0076: 
v2 25 May 2016
0077: 
- Removed problematic but unnecessary code from the mod's database modification program.
0078: 
  More specifically... Sometimes, but not always, PHP resets the user session when it encounters a
0079: 
  a <script> tag whose script can't be found. Standard admin programs contain such a tag:
0080: 
  <script type="text/javascript" src="js/admin.js"></script>
0081: 
  which fails when the program is run from a mod subfolder.
0082: 
  Fortunately, that script isn't needed by the mod's database modification program.
0083: 
- Actually, to avoid another instance of the same problem inside standard TNG code, I also
0084: 
  renamed that program and changed the mod to install it to the main TNG folder.
0085: 
v1b - 27 Mar 2016
0086: 
- Found a JavaScript bug; the submitClick validation function was not returning the value
0087: 
  returned by its call to the confirm function.  It was just a warning, so it wasn't awful.
0088: 
- Cleaned up the code by using (document).ready event handlers rather than events specified
0089: 
  in the form field HTML elements.
0090: 
- Also uses more advanced jQuery selectors in the event handlers so that I don't have to
0091: 
  force ID attributes into existing form field HTML elements.
0092: 
- Changed the Mod Parameters to strings rather than boolean values to be more tolerant of
0093: 
  data entry errors. Now "true" mean true, and anything else means false
0094: 
v1a - 22 Feb 2016
0095: 
- Uses Show Mod Names v2
0096: 
0097: 
***********************************************************************
0098: 
***********************************************************************
0099: 
%target:admin_dataimport.php%
0100: 
*** The program that displays the kickoff form that starts the Gedcom Import process ***
0101: 
*** Adds a checkbox that will cause the Gedcom Import to purge old medialinks.
0102: 
***   o If there are 'createdfromgedcom' fields whose value is 1, then the new checkbox
0103: 
***     is labeled "Purge Medialinks created by a previous Gedcom Import"
0104: 
***   o If no 'createdfromgedcom' field values are set, then the then the new checkbox
0105: 
***     is labeled "Purge all Medialinks"
0106: 
*** Adds an information hyperlink next to the new Purge Medialinks checkbox.
0107: 
0108: 
%parameter:$GedcomImportPurge:%
0109: 
%desc:This is just a dummy parameter to link you to
0110: 
<b style='font-style:1.1em;'><a href='admin_importconfig.php?open=robin13&mod=GedcomImportPurge'>this mod's options</a></b>.
0111: 
<p>This dummy parameter defaults to the empty string (); there is no point but no harm in changing it.</p>
0112: 
%
0113: 
0114: 
**** Start with a fileexists directive that looks for the Mod Settings Blocks Include file,
0115: 
**** and generate an error if that file is not present.
0116: 
%fileexists:rrmodsettingsblocks.php:location1%
0117: 
*** Dummy location guaranteed not to work
0118: 
%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>%
0119: 
{{dummy search string}}
0120: 
%end:%
0121: 
%replace:%
0122: 
{{dummy replacement string}}
0123: 
%end:%
0124: 
%label:location1%
0125: 
0126: 
%location:%
0127: 
include("begin.php");
0128: 
%end:%
0129: 
%insert:after%
0130: 
0131: 
##### admin_dataimport.php, modified by ###Gedcom Import Purge, by Robin Richmond
0132: 
# Adds a checkbox that controls the purging of old medialinks.
0133: 
$GedcomImportPurge = ''; #Dummy mod parameter that links to the mod options
0134: 
$tngModNames['Gedcom Import Purge']['admin_dataimport.php'] = '5e'; #Register this mod
0135: 
########################################################
0136: 
#Read custom language strings from a mods subfolder rather than from standard TNG custom text files.
0137: 
$modfolder = 'gedcom_import_purge_v13.0.0.5e';
0138: 
include("$modspath/$modfolder/languages/English_custtext.php");
0139: 
if ($mylanguage != "languages/English" && file_exists("$modspath/$modfolder/{$mylanguage}_custtext.php"))
0140: 
	include("$modspath/$modfolder/{$mylanguage}_custtext.php");
0141: 
#############################################################################
0142: 
#Initialize the mod options
0143: 
if (!isset($rrconfig['GedcomPurgeImportMedia'])) $rrconfig['GedcomPurgeImportMedia'] = '1';
0144: 
if (!isset($rrconfig['GedcomPurgeMedialinks'])) $rrconfig['GedcomPurgeMedialinks'] = '1';
0145: 
#############################################################################
0146: 
%end:%
0147: 
0148: 
******* admin_dataimport.php Location 2 - New onclick event for the submit button.
0149: 
%location:%
0150: 
<script type="text/javascript" src="js/admin.js?v<?php echo $tng_version; ?>"></script>
0151: 
%end:%
0152: 
%insert:after%
0153: 
<!-- ###Gedcom Import Purge Location 2: new document.ready function -->
0154: 
<script>
0155: 
////////////////////////////////////////////////////////////////////
0156: 
/////////////////// Document.ready function ////////////////////////
0157: 
$(function(){
0158: 
	//Check the Import Media checkbox if a mod parameter says to do so.
0159: 
<?php
0160: 
if ($rrconfig['GedcomPurgeImportMedia'])
0161: 
	echo "$(\"input[name='importmedia']\").prop('checked',true);\n";
0162: 
?>
0163: 
	// Onclick event for the form submit button.
0164: 
	$(':submit').click(function() {
0165: 
		//It's possible but unlikely that the user would want to purge medialinks when the
0166: 
		//Import Media checkbox is unchecked.
0167: 
		if (!$("[name='importmedia']").is(':checked') && $("#rrPurgeMedialinks").is(':checked') )
0168: 
			return confirm ("<?php echo $admtext['rrgip-purgewarn']; ?>");
0169: 
	})
0170: 
	// Onclick event handler for the Import Media checkbox.
0171: 
	// If the Import Media checkbox is off then the Purge Media Links box should be unchecked.
0172: 
	// The user can recheck it, but isn't likely to do so.
0173: 
	$("input[name='importmedia']").click(function() {
0174: 
		if (!$(this).is(':checked'))
0175: 
			$('#rrPurgeMedialinks').attr('checked',false);
0176: 
	})
0177: 
}); //End of (document).ready function
0178: 
</script>
0179: 
<!-- ###Gedcom Import Purge Location 2: End of insertion -->
0180: 
0181: 
%end:%
0182: 
0183: 
*************** admin_dataimport.php Location 3 - Insert an Inner Mod Menu
0184: 
%location:%
0185: 
	$menu = doMenu($datatabs,"import",$innermenu);
0186: 
%end:%
0187: 
%insert:before%
0188: 
	###Gedcom Import Purge Location 3: Insert an Inner Mod Menu
0189: 
	if (file_exists('rrinnermodmenu_lib.php')) {
0190: 
		include_once('rrinnermodmenu_lib.php');
0191: 
		$innermenu .= rrimmBuildInnerModMenu('Gedcom Import Purge', 1, 'importconfig', '', "https://tng.lythgoes.net/wiki/index.php?title=Gedcom_Import_Purge#Details");
0192: 
	}
0193: 
	###Gedcom Import Purge Location 3: End of insertion
0194: 
%end:%
0195: 
0196: 
******* admin_dataimport.php Location 4 - New checkboxes offering to purge Gedcom-imported links & suppress Citation Medialinks
0197: 
%location:%
0198: 
				<div><input type="checkbox" name="importlatlong" value="1"> <?php echo $admtext['importlatlong']; ?></div>
0199: 
%end:%
0200: 
%insert:before%
0201: 
<?php
0202: 
				###Gedcom Import Purge Location 4: Add two checkboxes
0203: 
				#The "Purge media links..." checkbox is displayed only if the createdfromgedcom field exists
0204: 
				#Check for the new database field. Set a variable that will be used in the medialinks SQL query
0205: 
				$query = "SHOW columns FROM $medialinks_table WHERE field = 'createdfromgedcom'";
0206: 
				$result = tng_query($query);
0207: 
				if (tng_num_rows($result) == 1) {
0208: 
					#The field label is immediately followed by a help link.
0209: 
					$checked = $rrconfig['GedcomPurgeMedialinks'] ? ' checked' : '';
0210: 
					echo "<div><label><input type='checkbox' id='rrPurgeMedialinks' name='rrPurgeMedialinks'
0211: 
						value='1'$checked>{$admtext['rrgip-purgelinks']}
0212: 
						<a href='#' title='Help page'
0213: 
							onclick=\"openHelp('languages/English/data_help.php#rrpurgemod');
0214: 
							return false;\"><img src='img/info_2.png' width='16' height='16'/></a>
0215: 
					</label></div>\n";
0216: 
				} else {
0217: 
					echo "<div style='font-weight:bold;color:brown;'>{$admtext['rrgip-nofield1']}<br>
0218: 
						{$admtext['rrgip-nofield2']} <a href='rrgedcomimportpurge_dbsetup.php?return=import'>{$admtext['rrgip-nofield3']}</a>{$admtext['rrgip-nofield4']}
0219: 
					</div>
0220: 
					<input type='hidden' name='rrPurgeMedialinks' value=''>\n";
0221: 
				}
0222: 
				tng_free_result($result);
0223: 
0224: 
				#2. Suppress citation medialinks
0225: 
				#The field label is immediately followed by a help link.
0226: 
				$checked = $rrconfig['GedcomPurgeNotCitations'] ? ' checked' : '';
0227: 
				echo "<div><label><input type='checkbox' name='notcitationlinks'
0228: 
					value='1'$checked>{$admtext['rrgip-nocitations']}
0229: 
					<a href='#' title='Help page'
0230: 
						onclick=\"openHelp('languages/English/data_help.php#rrCitationMedialinks');
0231: 
						return false;\"><img src='img/info_2.png' width='16' height='16'/></a>
0232: 
				</label></div>\n";
0233: 
				###Gedcom Import Purge Location 4: End of insertion
0234: 
?>
0235: 
%end:%
0236: 
0237: 
*************** admin_dataimport.php Location 5 - List mods that affect this program
0238: 
%location:%
0239: 
</table>
0240: 
</form>
0241: 
%end:%
0242: 
%insert:after%
0243: 
<?php ###Gedcom Import Purge Location 5 Show Mods
0244: 
if (file_exists('rrshowmodnames_include.php')) include_once ('rrshowmodnames_include.php');
0245: 
?>
0246: 
%end:%
0247: 
0248: 
***********************************************************************
0249: 
*************************************************************
0250: 
%target:admin_gedimport.php%
0251: 
*** The main program for the Gedcom Import process
0252: 
%location:%
0253: 
include("begin.php");
0254: 
%end:%
0255: 
%insert:after%
0256: 
0257: 
##### admin_gedimport.php, modified by ###Gedcom Import Purge, by Robin Richmond
0258: 
# The functional changes are in subroutine libraries.
0259: 
# The "main" program in this file is modified only to set a flag to say whether createdfromgedcom field is missing,
0260: 
# and to invoke the ShowModName code.
0261: 
# Note that this page might appear as a progress monitor popped up over the admin_dataimport.php form.
0262: 
# Messages generated by this mod are just for the full page, not for the popup.
0263: 
$tngModNames['Gedcom Import Purge']['admin_gedimport.php'] = '5e'; #Register this mod
0264: 
########################################################
0265: 
#Read custom language strings from a mods subfolder rather than from standard TNG custom text files.
0266: 
$modfolder = 'gedcom_import_purge_v13.0.0.5e';
0267: 
include("$modspath/$modfolder/languages/English_custtext.php");
0268: 
if ($mylanguage != "languages/English" && file_exists("$modspath/$modfolder/{$mylanguage}_custtext.php"))
0269: 
	include("$modspath/$modfolder/{$mylanguage}_custtext.php");
0270: 
#########################################################
0271: 
#Check for the new database field. Set a variable that will be used in the medialinks SQL query
0272: 
$query = "SHOW columns FROM $medialinks_table WHERE field = 'createdfromgedcom'";
0273: 
$result = tng_query($query);
0274: 
$rrFromGedcomFieldMissing = (tng_num_rows($result) != 1);
0275: 
tng_free_result($result);
0276: 
########################################################
0277: 
%end:%
0278: 
0279: 
*************** admin_gedimport.php Location 2 - Show mods at the bottom of the page
0280: 
%location:%
0281: 
echo tng_adminfooter();
0282: 
%end:%
0283: 
%insert:before%
0284: 
###Gedcom Import Purge Location 2: Show Mod Names
0285: 
if (file_exists('rrshowmodnames_include.php')) include_once ('rrshowmodnames_include.php');
0286: 
%end:%
0287: 
0288: 
***********************************************************************
0289: 
***********************************************************************
0290: 
%target:gedimport_misc.php%
0291: 
*** One of several function libraries used by the gedcom import ***
0292: 
*** We'll change it to set the createdfromgedcom flag in Medialinks
0293: 
0294: 
%location:%
0295: 
//set trim_it to a non-zero value to use this feature
0296: 
%end:%
0297: 
%insert:before%
0298: 
##### gedimport_misc.php, modified by ###Gedcom Import Purge, by Robin Richmond
0299: 
# In the processMedia function, the new 'createdfromgedcom' field is set to 1 for each Medialink
0300: 
# that the Gedcom Import process creates. (Medialinks.createdfromgedcom was created by this mod.)
0301: 
$tngModNames['Gedcom Import Purge']['gedimport_misc.php'] = '5e'; #Register this mod
0302: 
#############################################################################
0303: 
0304: 
%end:%
0305: 
0306: 
******* gedimport_misc.php Location 2 - In function saveCitation, conditionally suppress citation medialinks
0307: 
*** code fragment insertion with inline PHP comment
0308: 
*** $notcitationlinks is a querystring parameter generated by the kickoff form.
0309: 
%location:%
0310: 
is_array($cite['MEDIA'])
0311: 
%end:%
0312: 
%triminsert:after%
0313: 
 && (!isset($GLOBALS['notcitationlinks']) || !$GLOBALS['notcitationlinks'])/*###Gedcom Import Purge Locations 2: Conditionally suppress citation medialinks*/
0314: 
%end:%
0315: 
0316: 
******* gedimport_misc.php Location 2b
0317: 
%location:%
0318: 
		//insert ignore or update medialink
0319: 
%end:%
0320: 
%insert:after%
0321: 
		###Gedcom Import Purge Location 2b: The changes to the SQL query depend on whether the createdfromgedcom field exists
0322: 
		if ($GLOBALS['rrFromGedcomFieldMissing']) {
0323: 
			$rrInsertField = $rrInsertValue = $rrUpdateAssign = '';
0324: 
		} else {
0325: 
			$rrInsertField = ", createdfromgedcom";
0326: 
			$rrInsertValue = ", 1";
0327: 
			$rrUpdateAssign = ", createdfromgedcom=1";
0328: 
		}
0329: 
		###Gedcom Import Purge Location 2b: End of insertion
0330: 
%end:%
0331: 
0332: 
******* gedimport_misc.php Location 3 - Add the new createdfromgedcom field to the Medialinks INSERT statement
0333: 
*** code fragment, without comment, on the same line as the next location***
0334: 
%location:%
0335: 
eventID, defphoto
0336: 
%end:%
0337: 
%triminsert:after%
0338: 
$rrInsertField
0339: 
%end:%
0340: 
0341: 
******* gedimport_misc.php Location 4 - Add the createdfromgedcom value to the Medialinks INSERT statement
0342: 
*** code fragment, on the same line as the previous location. ***
0343: 
%location:%
0344: 
{$mm['defphoto']}\"
0345: 
%end:%
0346: 
%triminsert:after%
0347: 
$rrInsertValue /*###Gedcom Import Purge Locations 3&4: Add createdfromgedcom fieldname & value*/
0348: 
%end:%
0349: 
0350: 
******* gedimport_misc.php Location 5 - Add the createdfromgedcom field & value to a Medialinks UPDATE statement
0351: 
*** code fragment with inline SQL comment ***
0352: 
%location:%
0353: 
{$mm['NOTE']}\"$defphotostr
0354: 
%end:%
0355: 
%triminsert:after%
0356: 
$rrUpdateAssign /* ###Gedcom Import Purge Location 5: Add createdfromgedcom field */
0357: 
%end:%
0358: 
0359: 
***********************************************************************
0360: 
***********************************************************************
0361: 
%target:gedimport_trees.php%
0362: 
*** One of several function libraries used by the Gedcom import ***
0363: 
0364: 
%location:%
0365: 
function ClearData( $tree ) {
0366: 
%end:%
0367: 
%insert:before%
0368: 
##### gedimport_trees.php, modified by ###Gedcom Import Purge, by Robin Richmond
0369: 
# function ClearData now
0370: 
# - Deletes only those Medialinks that are flagged as being created by a Gedcom import
0371: 
# - Does not delete places with a geoignore, placelevel, or zoom value. */
0372: 
#############################################################################
0373: 
0374: 
%end:%
0375: 
0376: 
******* gedimport_trees.php Location 2 - Purge places and medialinks in the ClearData function
0377: 
%location:%
0378: 
	$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 = \"\")";
0379: 
	$result = tng_query($query);
0380: 
%end:%
0381: 
%replace:%
0382: 
	###Gedcom Import Purge location 2 - Purge places and medialinks
0383: 
	global $old, $media_table, $tngconfig, $admtext;
0384: 
	global $rrPurgeMedialinks; #A new form field value passed from the Gedcom Import kickoff form
0385: 
	$GLOBALS['tngModNames']['Gedcom Import Purge']['gedimport_trees.php(ClearData)'] = '5e'; #Register the mod
0386: 
0387: 
	#Don't purge places if there is more than one tree but only one places list, since
0388: 
	#purging places without regard to their use in other trees can break external reference
0389: 
	#from records in those trees.
0390: 
	if ($tngconfig['places1tree'] && $tree_cnt>1) {
0391: 
		$rrpurged = 0;
0392: 
	} else { #Purge places that do not have certain attributes, and that do not have medialinks.
0393: 
		if ($tngconfig['places1tree']) {
0394: 
			$rrSQLwhere = $rrSQLjoin = "";
0395: 
		} else {
0396: 
			$rrSQLjoin = " AND mm.gedcom = pp.gedcom";
0397: 
			$rrSQLwhere = " AND pp.gedcom = \"$tree\"";
0398: 
		}
0399: 
		$query = "DELETE pp FROM $places_table pp
0400: 
			LEFT JOIN $medialinks_table mm ON mm.personID = pp.place $rrSQLjoin
0401: 
			WHERE (latitude is null OR latitude = '') AND (longitude is null OR longitude = '')
0402: 
				AND (notes is null OR notes = '')
0403: 
				AND (zoom is null OR zoom=0) AND (placelevel is null or placelevel=0)
0404: 
				AND geoignore=0
0405: 
				AND mm.medialinkID is null $rrSQLwhere";
0406: 
		$result = tng_query($query);
0407: 
		$rrpurged = tng_affected_rows();
0408: 
	}
0409: 
	if ($old) {
0410: 
		echo "<div>{$admtext['rrgip-intree']}: $tree</div>";
0411: 
		echo "<div>" . str_replace("##", $rrpurged, $admtext['rrgip-purgedplaces']) . "</div>\n";
0412: 
	}
0413: 
	#Purge media links created by a Gedcom Import. Make sure that the createdfromgedcom field exists.
0414: 
	$query = "SHOW columns FROM $medialinks_table WHERE field = 'createdfromgedcom'";
0415: 
	$result = tng_query($query);
0416: 
	$rrFieldIsPresent = (tng_num_rows($result) == 1);
0417: 
	tng_free_result($result);
0418: 
	if ($rrPurgeMedialinks && rrFieldIsPresent) {
0419: 
		#Check for any value>0 so other processes can flag condition that are meaningful to them.
0420: 
		$query = "DELETE FROM $medialinks_table
0421: 
			WHERE gedcom = '$tree' AND createdfromgedcom>0";
0422: 
		$result = tng_query($query);
0423: 
		#Report how many medialinks were deleted and how many remain in this tree
0424: 
		if ($old){
0425: 
			echo "<div>" . str_replace("##",tng_affected_rows(),$admtext['rrgip-purgedlinks']) . "</div>\n";
0426: 
			$query = "SELECT count(medialinkID) as linkcount from $medialinks_table WHERE gedcom = '$tree'";
0427: 
			$result = tng_query($query);
0428: 
			$rrRow = tng_fetch_assoc( $result );
0429: 
			echo "<div>" . str_replace("##", $rrRow['linkcount'], $admtext['rrgip-linksnow']) . "</div>\n";
0430: 
		}
0431: 
	} #end if purge links
0432: 
	###Gedcom Import Purge Location 2 - End of replacement text
0433: 
%end:%
0434: 
0435: 
***********************************************************************
0436: 
**************************************************************************
0437: 
%target:languages/English/data_help.php%
0438: 
*** The help file for Gedcom import and export ***
0439: 
0440: 
%location:%
0441: 
include("../../helplib.php");
0442: 
%end:%
0443: 
%insert:before%
0444: 
##### admin_dataimport.php, modified by ###Gedcom Import Purge, by Robin Richmond
0445: 
# A new section describes features implemented by this mod, and the form field that controls those features.
0446: 
$tngModNames['Gedcom Import Purge']['data_help.php'] = '5e';
0447: 
#############################################################################
0448: 
0449: 
%end:%
0450: 
0451: 
******* data_help.php Location 2 - A new section for this mod
0452: 
%location:%
0453: 
		<a name="export"><p class="subheadbold">GEDCOM Export</p></a>
0454: 
%end:%
0455: 
%insert:before%
0456: 
		<!-- ###Gedcom Import Purge Location 2: New Section about the mod -->
0457: 
		<div style='border:1px solid blue; padding:8px;'>
0458: 
		<h2 id="rrpurgemod" style='color:blue;'>Changes made by the Gedcom Import Purge mod</h2>
0459: 
		<h4 style="margin-bottom:0;">1. Purging Place Records</h4>
0460: 
		The Gedcom Import Purge changes the Gedcom Import process to limit the number of places that are purged.
0461: 
		As the import starts, it no longer purges
0462: 
			<ul><li>Any Places on sites where there are multiple trees, and just one Place list
0463: 
				(since such places might be used by trees other than the one being imported),</li>
0464: 
			<li>Places with a placelevel value (since placelevels cannot be obtained from a Gedcom file), or</li>
0465: 
			<li>Places with a Medialink (since Place medialinks can only be created from within TNG, not through Gedcom import).</li>
0466: 
			</ul></li>
0467: 
		</ol>
0468: 
0469: 
		<h4 style="margin-bottom:0;">2. Purging Medialinks</h4>
0470: 
		The native Gedcom Import Process purges all Person, Family, Source, Repository, Citation, and Event data from the tree being loaded,
0471: 
		because all such data is expected to be supplied by the Gedcom file.
0472: 
		There is simply no decent way to mix Gedcom import of these record types with TNG data entry
0473: 
		(at least when you are importing an entire tree.)
0474: 
		<p>But media information is different.
0475: 
		It is very common for TNG administrators to import some media items and medialinks from Gedcom files,
0476: 
		and to do manual uploading and data entry of some media items, their descriptions, and their links to other database objects.
0477: 
		Since TNG does not natively provide a way to distinuish media items and medialinks
0478: 
		that are created through Gedcom Imports from those that are created through TNG data entry,
0479: 
		all a native TNG Gedcom import can do is to leave <b>all</b> media items and medialinks intact,
0480: 
		causing Medialinks records that have been removed from the source database to remain in TNG after the import.
0481: 
		</p>
0482: 
		<p style='margin-bottom:0;';>The Gedcom Import Purge mod addresses this problem by</p>
0483: 
			<ol style='margin-top:0;'>
0484: 
			<li>Installing a one-time setup program that creates a new database field in the Medialinks table
0485: 
			 that indicates whether a medialink was created during a Gedcom import
0486: 
			or was defined "manually" - through TNG data entry programs.
0487: 
			The new field is named "createdfromgedcom", and it is set to 1 for medialinks created
0488: 
			during a Gedcom Import.</li>
0489: 
			<li>Purging (at the beginning of a Gedcom Import) all medialinks that are flagged
0490: 
			as being created by a Gedcom Import
0491: 
			(but doing so only if the user checks the mods "Purge Medialinks" checkbox in the Gedcom Import kickoff form.</li>
0492: 
			<li>Adding a form field in the Medialinks section of the Edit Media form so that
0493: 
			users can view each medialink's "createdfromgedcom" flag.
0494: 
			(The form allows the user to set or reset that flag, but the flag really represents
0495: 
			how the medialink was created, so it would be fairly unusual to change its setting.)</li>
0496: 
			</ol>
0497: 
		
0498: 
		<h4 style="margin-bottom:0;" id='rrCitationMedialinks'>3. The Gedcom Import Purge mod and Citation Medialinks</h4>
0499: 
			For a period of time between incremental versions of TNGv12, the Gedcom Import would invalidate
0500: 
			all existing Citation Medialinks and leave in place, and the invalid Medialinks would sometimes
0501: 
			show up TNG pages such as Person Profiles.
0502: 
			To respond to this problem, the Gedcom Import Purge mod added a "Suppress the creation of citation medialinks"
0503: 
			button on the Gedcom Import kickoff form, and changed the Gedcom Import process to act on that button.
0504: 
		<p>This problem has been resolved, so, really, there is virtually no reason to have the
0505: 
			"Suppress the creation of citation medialinks" checkbox any more.
0506: 
			About the only thing it accomplishes is to suppress linked media item thumbnails on source citations in the Person Profile.
0507: 
		</p>
0508: 
		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>
0509: 
		</div>
0510: 
	</td>
0511: 
</tr>
0512: 
<tr class="databack">
0513: 
	<td class="tngshadow">
0514: 
0515: 
		<p style="float:right"><a href="#top">Top</a></p>
0516: 
		<!-- ### Gedcom Import Purge Location 2: End of insertion -->
0517: 
%end:%
0518: 
0519: 
******* data_help.php Location 3 - Show mod names.
0520: 
%location:%
0521: 
</body>
0522: 
%end:%
0523: 
%insert:before%
0524: 
<?php
0525: 
###Gedcom Import Purge Location 3: Show mod names
0526: 
if (file_exists('rrshowmodnames_include.php')) include_once ('rrshowmodnames_include.php');
0527: 
?>
0528: 
%end:%
0529: 
0530: 
***********************************************************************
0531: 
***********************************************************************
0532: 
%target:admin_editmedia.php%
0533: 
0534: 
*** - The MediaLinks table is in a subform that generated by micro_medialinks.php.
0535: 
*** - The "Purge on Gedcom" checkbox (like "Show" and others) is an "immediate action" field; that is,
0536: 
***   the database field is updated as soon as the checkbox is checked or unchecked.
0537: 
*** - mediafind.js and mediautils.js, get and save the checkbox values.
0538: 
0539: 
%location:%
0540: 
include("begin.php")
0541: 
%end:%
0542: 
%insert:after%
0543: 
0544: 
##### admin_editmedia.php, modified by ###Gedcom Import Purge, by Robin Richmond
0545: 
# Adds a checkbox in the MediaLinks subform for the "Purge on Gedcom Import" field.
0546: 
# Most of the work to add the checkbox is done in micro_medialinks.php and to two
0547: 
# Javascript files, mediautils.js and mediafind.js.
0548: 
$tngModNames['Gedcom Import Purge']['admin_editmedia.php'] = '5e';
0549: 
########################################################
0550: 
#Read custom language strings from a mods subfolder rather than from standard TNG custom text files.
0551: 
$modfolder = 'gedcom_import_purge_v13.0.0.5e';
0552: 
include("$modspath/$modfolder/languages/English_custtext.php");
0553: 
if ($mylanguage != "languages/English" && file_exists("$modspath/$modfolder/{$mylanguage}_custtext.php"))
0554: 
	include("$modspath/$modfolder/{$mylanguage}_custtext.php");
0555: 
########################################################
0556: 
#Check for the new database field. Set a variable that will be used in the medialinks SQL query
0557: 
$query = "SHOW columns FROM $medialinks_table WHERE field = 'createdfromgedcom'";
0558: 
$result = tng_query($query);
0559: 
if (tng_num_rows($result) == 1) {
0560: 
	$rrQueryField = "createdfromgedcom";
0561: 
	$rrFromGedcomFieldMissing = false;
0562: 
} else {
0563: 
	$rrQueryField = "0 AS createdfromgedcom";
0564: 
	$rrFromGedcomFieldMissing = true;
0565: 
}
0566: 
tng_free_result($result);
0567: 
########################################################
0568: 
%end:%
0569: 
0570: 
******* admin_editmedia.php Location 2 - Add the new Gedcom Purge database field to the SQL query
0571: 
*** Code fragment insertion. The search string is at the very end of a line of SQL code,
0572: 
*** and ends with the last field in the SELECT list. The insertion adds a comma to the
0573: 
*** end of the existing line, add adds a new line with a new fieldname and an SQL comment.
0574: 
*** The variable rrQueryField causes all medialinks to appear to have createdfromgedcom=0
0575: 
*** if the createdfromgedcom field does not exist.
0576: 
%location:%
0577: 
$families_table.private as fprivate
0578: 
%end:%
0579: 
%triminsert:after%
0580: 
,
0581: 
	$rrQueryField /* ###Gedcom Import Purge Location 2: Add the new createdfromgedcom field to the query */
0582: 
%end:%
0583: 
0584: 
******* admin_editmedia.php Location 3 - Show mod names
0585: 
%location:%
0586: 
</td>
0587: 
</tr>
0588: 
</table>
0589: 
</form>
0590: 
0591: 
%end:%
0592: 
%insert:after%
0593: 
<?php
0594: 
### Gedcom Import Purge Location 3: Show Mod Names
0595: 
if (file_exists('rrshowmodnames_include.php')) include_once ('rrshowmodnames_include.php');
0596: 
?>
0597: 
%end:%
0598: 
0599: 
***********************************************************************
0600: 
***********************************************************************
0601: 
%target:js/mediafind.js%
0602: 
*** When a new medialink is created, a new row is inserted into the medialinks data table, in the
0603: 
*** medialinks subform of the Cemetery Edit page.
0604: 
*** The code inserted into this file inserts a cell for the "From Gedcom" column, but does not
0605: 
*** populate that table cell. It is populated by mediautils.js.
0606: 
0607: 
%location:%
0608: 
function getPotentialLinks(linktype) {
0609: 
%end:%
0610: 
%insert:before%
0611: 
/*##### mediafind.js, modified by ###Gedcom Import Purge, by Robin Richmond*/
0612: 
/* Insert a data cell for the "From Gedcom" column into the new medialinks table row created for a new medialink.
0613: 
$tngModNames['Gedcom Import Purge']['mediafind.js'] = '5e'; (just a comment)
0614: 
############################################################################# */
0615: 
0616: 
%end:%
0617: 
0618: 
**********************js/mediafind.js Location 2: Add an HTML table cell cell for the Purge on Gedcom Field
0619: 
%location:%
0620: 
						td7.setAttribute('align','center');
0621: 
%end:%
0622: 
%insert:after%
0623: 
						//###Gedcom Import Purge Location 2: Add an HTML table cell cell for the createdfromgedcom field,
0624: 
						//so the user can set or unset the checkbox
0625: 
						if (!rrFromGedcomFieldMissing) {
0626: 
							var td8 = insertCell(newtr,8,"lightback normal",'<input type="checkbox" name="gedcom'+linkID+'" id="gedcom'+linkID+'" onclick="toggleGedcom(this);" value="1""/>');
0627: 
							td8.id = 'gedcom'+linkID;
0628: 
							td8.setAttribute('align','center');
0629: 
						}
0630: 
						//###Gedcom Import Purge Location 2: End of insertion
0631: 
%end:%
0632: 
0633: 
***********************************************************************
0634: 
***********************************************************************
0635: 
%target:js/mediautils.js%
0636: 
*** The new funtion function toggleGedcom invokes the misnamed AJAX file ajx_updateorder.php which 
0637: 
*** places the new CreatedFromGedcom checkbox that is in the medialinks subform of the Media Edit page.
0638: 
*** Each field in the medialinks subform is saved to the database the moment it is changed.
0639: 
*** (That is, there is an onchange or onclick event for each field that triggers an Ajax
0640: 
*** call that saves only one field to one record.)
0641: 
*** The database field medialinks.createdfromgedcom is created by this mod. It is a tinyint field that
0642: 
*** is set to 1 by the Gedcom Import process whenever a Gedcom Import saves a medialink record.
0643: 
*** (Other processes can set it to other positive integers to flag special cases.)
0644: 
0645: 
%location:%
0646: 
var gsControlName = "";
0647: 
%end:%
0648: 
%insert:before%
0649: 
/*##### mediautils.js, modified by ###Gedcom Import Purge, by Robin Richmond*/
0650: 
/* The new funtion function toggleGedcom invokes the AJAX file ajx_updateorder.php to populate a new
0651: 
table cell for the new createdfromgedcom field.
0652: 
$tngModNames['Gedcom Import Purge']['mediautils.js'] = '5e'; (just a comment)
0653: 
############################################################################# */
0654: 
0655: 
%end:%
0656: 
0657: 
**********************js/mediautils.js Location 2 - New Javascript function
0658: 
%location:%
0659: 
function toggleShow(checkbox) {
0660: 
%end:%
0661: 
%insert:before%
0662: 
0663: 
//###Gedcom Import Purge Location 2: New Function to invoke Ajax to save the createdbygedcom flag from a medialinks record
0664: 
//////////////////////////////////////////////////////////////////////////////////////
0665: 
//Each checkbox in the medialinks subform of the Media Edit form has its own function, whose name matches the
0666: 
//fieldname and elementID prefix of the corresponding data field. The functions for each field are virutually
0667: 
//identical - in fact, the only real differences among them are the base fieldname & values, and the fact that
0668: 
//one of the fields has a negative value (that is, when the checkbox is checked, the database value should be zero.
0669: 
//Each function grabs the medialinkID from the checkbox's fieldname, and passes the medialinkID, the checkbox
0670: 
//status, and the base fieldname (as an 'action' value) to the multi-purpose Ajax program ajx_updateorder.php.
0671: 
function toggleGedcom(checkbox) {
0672: 
	var toggle = checkbox.checked ? 1 : 0;
0673: 
	var medialinkID = checkbox.name.substr(6); //Strip 'gedcom' from the front of the fieldname
0674: 
	var params = {medialinkID:medialinkID, toggle:toggle, action:'gedcom'};
0675: 
	jQuery.ajax({
0676: 
		url: cmstngpath + 'ajx_updateorder.php',
0677: 
		data: params
0678: 
	});
0679: 
} //end function toggleGedcom
0680: 
//###Gedcom Import Purge Location 2: End of insertion
0681: 
0682: 
%end:%
0683: 
0684: 
***********************************************************************
0685: 
***********************************************************************
0686: 
%target:micro_medialinks.php%
0687: 
0688: 
%location:%
0689: 
$linkrows = "";
0690: 
%end:%
0691: 
%insert:before%
0692: 
##### micro_medialinks.php, modified by ###Gedcom Import Purge, by Robin Richmond
0693: 
# Adds a "Purge on Gedcom" checkbox column to the HTML layout table for the MediaLinks form.
0694: 
$tngModNames['Gedcom Import Purge']['micro_medialinks.php'] = '5e';
0695: 
###################################################################
0696: 
0697: 
%end:%
0698: 
0699: 
************************ micro_medialinks.php Location 2 - Add a table cell with a checkbox for the 'Created by Gedcom' field
0700: 
*** Multi-line code fragment replacement with HTML comment.
0701: 
*** The search string is at the end of a line of PHP code, and represented the end of a <td> element plus
0702: 
*** the </tr> tag (within a PHP string).
0703: 
*** The replacement string replaces the code fragment for the <td> element (which was only in the search
0704: 
*** string to define a unique string), adds code for a new <td> element, and generates the </tr> tag.
0705: 
*** As usual, the replacement string ends with a comment.
0706: 
%location:%
0707: 
value=\"1\"$schecked\"/></td></tr>\n";
0708: 
%end:%
0709: 
%trimreplace:%
0710: 
value=\"1\"$schecked\"/></td>";
0711: 
			###Gedcom Import Purge Location 2: For existing medialinks add a data table cell with a checkbox for the 'createdfromgedcom' field
0712: 
			###(this is a multiline code fragment insertion)
0713: 
			if (!$rrFromGedcomFieldMissing) {
0714: 
				$rrchecked = $plink['createdfromgedcom']>0 ? " checked" : "";
0715: 
				$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";
0716: 
			}
0717: 
			###Gedcom Import Purge Location 2: End of insertion
0718: 
%end:%
0719: 
0720: 
************************ micro_medialinks.php Location 3:
0721: 
%location:%
0722: 
		tng_free_result($result2);
0723: 
	}
0724: 
%end:%
0725: 
%insert:after%
0726: 
	###Gedcom Import Purge Location 3: Warning message if the From Gedcom field is missing
0727: 
	if ($rrFromGedcomFieldMissing)
0728: 
		echo "<div style='font-weight:bold;color:brown;'>{$admtext['rrgip-nofield1']}<br>
0729: 
		{$admtext['rrgip-nofield2']} <a href='rrgedcomimportpurge_dbsetup.php?return=media'>{$admtext['rrgip-nofield3']}</a>{$admtext['rrgip-nofield4']}
0730: 
		</div>\n";
0731: 
	##Also generate inline Javascript to save the missing field flag in a global Javascript variable
0732: 
	echo "<script>rrFromGedcomFieldMissing = $rrFromGedcomFieldMissing;</script>\n";
0733: 
	###Gedcom Import Purge Location 3: End of insertion
0734: 
%end:%
0735: 
0736: 
************************ micro_medialinks.php Location 4: Add the Created by Gedcom column heading to the MediaLinks form -->
0737: 
%location:%
0738: 
			<td class="fieldnameback fieldname nw">&nbsp;<b><?php echo $admtext['show']; ?></b>&nbsp;</td>
0739: 
%end:%
0740: 
%insert:after%
0741: 
<?php
0742: 
			###Gedcom Import Purge Location 4: Add the From Gedcom column heading to the MediaLinks form
0743: 
			if (!$rrFromGedcomFieldMissing)
0744: 
				echo "<td class='fieldnameback fieldname'>{$admtext['rrgip-fromgedcom']}</td>\n";
0745: 
			###Gedcom Import Purge Location 4: End of insertion
0746: 
?>
0747: 
%end:%
0748: 
0749: 
***********************************************************************
0750: 
***********************************************************************
0751: 
%target:ajx_updateorder.php%
0752: 
0753: 
%location:%
0754: 
include("begin.php");
0755: 
%end:%
0756: 
%insert:before%
0757: 
##### ajx_updateorder.php, modified by ###Gedcom Import Purge, by Robin Richmond
0758: 
#Adds an Action to update the Gedcom flag in the medialinks table "Purge on Gedcom" checkbox
0759: 
#column to the HTML layout table for the MediaLinks form.
0760: 
$tngModNames['Gedcom Import Purge']['ajx_updateorder.php'] = '5e';
0761: 
#############################################################################
0762: 
0763: 
%end:%
0764: 
0765: 
******************* ajx_updateorder.php Location 2
0766: 
%location:%
0767: 
	case "show":
0768: 
%end:%
0769: 
%insert:before%
0770: 
###Gedcom Import Purge Location 2: New Action to update the Gedcom flag in the medialinks table
0771: 
	case "gedcom":
0772: 
		$query = "UPDATE $medialinks_table SET createdfromgedcom = $toggle WHERE medialinkID=\"$medialinkID\"";
0773: 
		$result = @tng_query($query);
0774: 
		$rval = $query . $result;
0775: 
		break;
0776: 
###Gedcom Import Purge Location 2: End of insertion
0777: 
%end:%
0778: 
0779: 
**********************************************************************
0780: 
**********************************************************************
0781: 
%target:admin_importconfig.php%
0782: 
*** The Admin >> Settings >> Import Settings form
0783: 
%location:%
0784: 
include("begin.php");
0785: 
%end:%
0786: 
%insert:before%
0787: 
$tngModNames['Gedcom Import Purge']['admin_importconfig.php'] = '5e'; #Three checkboxes
0788: 
%end:%
0789: 
0790: 
*************** admin_importconfig.php Location 2 - The mod options
0791: 
%location:%
0792: 
</td>
0793: 
</tr>
0794: 
0795: 
</table>
0796: 
%end:%
0797: 
%insert:after%
0798: 
0799: 
<?php ###############################################################
0800: 
###Gedcom Import Purge Location 2: Three checkboxes that affect for the Gedcom Import kickoff form
0801: 
include_once('rrmodsettingsblocks.php'); #Handle the mod options
0802: 
########################################################
0803: 
#Read custom language strings from a mods subfolder rather than from standard TNG custom text files.
0804: 
$modfolder = 'gedcom_import_purge_v13.0.0.5e';
0805: 
include("$modspath/$modfolder/languages/English_custtext.php");
0806: 
if ($mylanguage != "languages/English" && file_exists("$modspath/$modfolder/{$mylanguage}_custtext.php"))
0807: 
	include("$modspath/$modfolder/{$mylanguage}_custtext.php");
0808: 
0809: 
if (!isset($rrconfig['GedcomPurgeImportMedia'])) $rrconfig['GedcomPurgeImportMedia'] = '1';
0810: 
if (!isset($rrconfig['GedcomPurgeMedialinks'])) $rrconfig['GedcomPurgeMedialinks'] = '1';
0811: 
if (!isset($rrconfig['GedcomPurgeNotCitations'])) $rrconfig['GedcomPurgeNotCitations'] = '0';
0812: 
0813: 
echo "<table class='rrmsbConfigTable' modname='Gedcom Import Purge' group='Gedcom'>
0814: 
	<tbody>
0815: 
		<input type='hidden' name='rrconfig[Gedcom Import Purge]'
0816: 
		value='GedcomPurgeImportMedia, GedcomPurgeMedialinks, GedcomPurgeNotCitations'>\n";
0817: 
0818: 
	#An introductory note
0819: 
	echo "<tr><td>{$admtext['rrgip-optionsnote']}</td>
0820: 
		<td></td></tr>\n";
0821: 
0822: 
	#The 'Import media if present' checkbox
0823: 
	$checked = ($rrconfig['GedcomPurgeImportMedia']) ? ' checked' : '';
0824: 
	echo "<tr><td><label for='rrconfig[GedcomPurgeImportMedia]'>{$admtext['rrgip-importoption']}</label></td>
0825: 
		<td><input type='checkbox' name='rrconfig[GedcomPurgeImportMedia]' value='1'$checked>
0826: 
		</td></tr>\n";
0827: 
0828: 
	#The 'Purge media links created by previous Gedcom imports' checkbox
0829: 
	$checked = ($rrconfig['GedcomPurgeMedialinks']) ? ' checked' : '';
0830: 
	echo "<tr><td><label for='rrconfig[GedcomPurgeMedialinks]'>{$admtext['rrgip-purgelinks']}</td>
0831: 
		<td><input type='checkbox' name='rrconfig[GedcomPurgeMedialinks]' value='1'$checked>
0832: 
		</td></tr>\n";
0833: 
0834: 
	#The 'Suppress Citation Medialinks' checkbox
0835: 
	$checked = ($rrconfig['GedcomPurgeNotCitations']) ? ' checked' : '';
0836: 
	echo "<tr><td><label for='rrconfig[GedcomPurgeNotCitations]'>{$admtext['rrgip-nocitations']}</td>
0837: 
		<td><input type='checkbox' name='rrconfig[GedcomPurgeNotCitations]' value='1'$checked>
0838: 
		</td></tr>\n";
0839: 
0840: 
	echo "</tbody>
0841: 
</table>\n";
0842: 
0843: 
# Use a Javascript document.ready function to remove a footnote that sits below the
0844: 
# form's Save button (and below the mod settings blocks for all Gedcom Import mods)
0845: 
# and insert it in the form right below the fields that it refers to.
0846: 
# This code is replicated exactly in the Gedcom Import Purge, Gedcom Import Monitor,
0847: 
# and Gedcom Import Mediatype mods.
0848: 
?>
0849: 
<script>
0850: 
$(function() {
0851: 
	var footnote = $("p:contains('<?php echo $admtext['commas']; ?>')");
0852: 
	if (footnote.length) {
0853: 
		footnote.remove();
0854: 
		var html = "<tr><td colspan='2'>* <?php echo $admtext['commas']; ?></td></tr>";
0855: 
		var td = $("form tr:contains('<?php echo $admtext['nopathmatch']; ?>')").before(html);
0856: 
	}
0857: 
});
0858: 
0859: 
//////////////////////////////////////////////////
0860: 
//function rrgipOpenWikiPage opens a TNG Wiki page as a popup.
0861: 
//It is invoked (at least) by the blue information icon next to the new "Suppress Citation Medialinks" checkbox.
0862: 
function rrgipOpenWikiPage(article, anchor='') {
0863: 
	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');
0864: 
	newwindow.focus();
0865: 
	return false;
0866: 
} //end function rrmsbOpenWikiPage
0867: 
0868: 
</script>
0869: 
<?php
0870: 
if (file_exists('rrshowmodnames_include.php')) include_once ('rrshowmodnames_include.php');
0871: 
###Gedcom Import Purge Location 2: End of Insertion
0872: 
?>
0873: 
%end:%
0874: 
0875: 
*************************************************************************
0876: 
*************************************************************************
0877: 
%target:admin_updateimportconfig.php%
0878: 
*** Saves the Import/Export Configuration Settings to the file importconfig.php
0879: 
%location:%
0880: 
include("begin.php");
0881: 
%end:%
0882: 
%insert:before%
0883: 
$tngModNames['###Gedcom Import Purge']['admin_updateimportconfig.php'] = '5e';
0884: 
######################################################################
0885: 
0886: 
%end:%
0887: 
0888: 
*************** admin_updateimportconfig.php Location 2 - Save any new settings for this mod
0889: 
*** I'm not crazy about using this search text, but Darrin changed fwrite( $fp, "?>\n" ); in TNGv13
0890: 
*** to fwrite( $fp, "?>" );
0891: 
*** (without \n) in TNGv13.0.1, and at least this line is consistent between the two versions.
0892: 
%location:%
0893: 
	fwrite( $fp, "\$tngimpcfg['coerce'] = \"$coerce\";\n" );
0894: 
%end:%
0895: 
%insert:after%
0896: 
###Gedcom Import Purge Location 2: Use a field to find the fields to save
0897: 
foreach (array_map('trim', explode(',', $rrconfig['Gedcom Import Purge'])) as $param)
0898: 
	fwrite( $fp, "\$rrconfig['$param'] = '{$rrconfig[$param]}';\n" );
0899: 
###Gedcom Import Purge Location 2: End of Insertion
0900: 
0901: 
%end:%
0902: 
0903: 
**********************************************************************
0904: 
**********************************************************************
0905: 
%target:files%
0906: 
%newfile:rrgedcomimportpurge_dbsetup.php%
0907: 
%fileversion:v13.0.0.5e%
0908: 
<?php
0909: 
##### gedcom_import_purge_dbsetup.php, modified by ###Gedcom Import Purge, by Robin Richmond
0910: 
// %version:v13.0.0.5e%
0911: 
# Creates or deletes a flag field in the Medialinks table that marks medialinks
0912: 
# created by the Gedcom import process rather than the TNG editor(s).
0913: 
# Installed by the Gedcom Import-Purge mod.
0914: 
# Must be run after the mod is installed but before the next Gedcom Import.
0915: 
# If the field exists, the program will note that, and invoke itself with a querystring
0916: 
# parameter whose value in English is "Delete It".
0917: 
# If the field does not exist, the program will note that, and invoke itself with a
0918: 
# querystring parameter whose value in English is "Create It".
0919: 
#
0920: 
# v5e - 29 Oct 2020
0921: 
# Added error checking, and moved the file into the .cfg file
0922: 
# v12 - Jun 2016
0923: 
# In order to avoid a weird PHP/TNG conflict that causes Admin programs
0924: 
# running outside of the standard TNG folder to reset the user session,
0925: 
# this program was
0926: 
# - modified to run in the standard TNG folder, and
0927: 
# - renamed so that its origins are clear.
0928: 
$tngModNames['Gedcom Import-Purge']['gedcom_import_purge_dbsetup.php'] = '5e'; #Register this mod
0929: 
0930: 
include("begin.php");
0931: 
include($cms['tngpath'] ."adminlib.php");
0932: 
$textpart = "textplus";
0933: 
include($cms['tngpath'] ."getlang.php");
0934: 
include($cms['tngpath'] ."$mylanguage/admintext.php");
0935: 
$admin_login = 1;
0936: 
include($cms['tngpath'] ."checklogin.php");
0937: 
include($cms['tngpath'] ."version.php");
0938: 
require($cms['tngpath'] ."adminlog.php");
0939: 
########################################################
0940: 
#Read custom language strings from a mods subfolder rather than from standard TNG custom text files.
0941: 
$modfolder = 'gedcom_import_purge_v13.0.0.5e';
0942: 
include("$modspath/$modfolder/languages/English_custtext.php");
0943: 
if ($mylanguage != "languages/English" && file_exists("$modspath/$modfolder/{$mylanguage}_custtext.php"))
0944: 
	include("$modspath/$modfolder/{$mylanguage}_custtext.php");
0945: 
########################################################
0946: 
0947: 
$flags['tabs'] = $tngconfig['tabs'];
0948: 
tng_adminheader( $admtext['rrgip-heading1'], $flags );
0949: 
echo "</head>\n";
0950: 
0951: 
echo tng_adminlayout();
0952: 
0953: 
$purgetabs[0] = array(1,"rrgedcomimportpurge_dbsetup.php", $admtext['rrgip-tab0'],"setup");
0954: 
$innermenu = "<a href=\"#\" onclick='window.close();' class=\"lightlink\">{$admtext['rrgip-returntomm']}</a>";
0955: 
$menu = doMenu($purgetabs,"setup",$innermenu);
0956: 
0957: 
echo displayHeadline($admtext['rrgip-heading1'] , "{$cms['tngpath']}img/photos_icon.gif",$menu,$message);
0958: 
?>
0959: 
0960: 
<table width="100%" border="0" cellpadding="10" cellspacing="2" class="lightback">
0961: 
<tr class="databack">
0962: 
<td class="tngshadow normal">
0963: 
    <span class="subhead"><strong><?php echo $admtext['rrgip-heading2']; ?></strong></span><br/><br/>
0964: 
<?php
0965: 
	$fieldname = "createdfromgedcom";
0966: 
	//Before displaying the form, take any action that was specified by button b1
0967: 
	if ($b1 == $admtext['rrgip-create']){
0968: 
		//Double-check that it does not exist
0969: 
		$query = "SHOW columns FROM $medialinks_table WHERE field = \"$fieldname\"";
0970: 
		$result = tng_query($query);
0971: 
		if (tng_num_rows($result) == 0) {
0972: 
			//Create the field
0973: 
			$query = "ALTER TABLE $medialinks_table ADD $fieldname TINYINT NOT NULL DEFAULT '0' COMMENT 'Created by the Gedcom Import Purge mod'";
0974: 
			echo "<div>SQL Command: $query </div>\n";
0975: 
			$result = @tng_query($query);
0976: 
			if( $result )
0977: 
				echo "...{$admtext['rrgip-done']}\n";
0978: 
			else
0979: 
				echo "...<strong>{$admtext['rrgip-notcreated']}</strong>\n";
0980: 
		} else {
0981: 
			echo "<p><strong>{$admtext['rrgip-alreadyexists']}</strong></p>\n";
0982: 
		}
0983: 
	} elseif ($b1 == $admtext['rrgip-delete']) {
0984: 
		//Double-check that it still exists
0985: 
		$query = "SHOW columns FROM $medialinks_table WHERE field = \"$fieldname\"";
0986: 
		$result = tng_query($query);
0987: 
		if (tng_num_rows($result) == 1) {
0988: 
			//Delete the field.
0989: 
			$query = "ALTER TABLE $medialinks_table DROP $fieldname";
0990: 
			echo "<div>SQL Command: $query </div>\n";
0991: 
			$result = @tng_query($query);
0992: 
			if( $result ) echo "...{$admtext['rrgip-done']}\n";
0993: 
			else echo "...<strong>{$admtext['rrgip-notdeleted']}</strong>\n";
0994: 
		} else {
0995: 
			echo "<p><strong>{$admtext['rrgip-alreadygone']}</strong></p>\n";
0996: 
		}
0997: 
	}
0998: 
	############# End of actions  ############
0999: 
1000: 
	#Check for the field and display the appropriate action button
1001: 
	$query = "SHOW columns FROM $medialinks_table WHERE field = \"$fieldname\"";
1002: 
	$result = tng_query($query);
1003: 
	$fieldIsPresent = (tng_num_rows($result) == 1);
1004: 
	tng_free_result($result);
1005: 
1006: 
	echo "<form>\n";
1007: 
		echo "<p style='font-size:115%; font-weight:bold;'>";
1008: 
		if ($fieldIsPresent) {
1009: 
			echo "{$admtext['rrgip-exists']}&emsp;
1010: 
				<input type=\"submit\" name=\"b1\" value=\"{$admtext['rrgip-delete']}\" />";
1011: 
		}
1012: 
		else {
1013: 
			echo "{$admtext['rrgip-notexist']}&emsp;
1014: 
				<input type=\"submit\" name=\"b1\" value=\"{$admtext['rrgip-create']}\" />";
1015: 
		}
1016: 
	echo "</p></form>
1017: 
	<p style='font-weight:bold;'>{$admtext['rrgip-close']}</p>
1018: 
";
1019: 
?>
1020: 
</td>
1021: 
</tr>
1022: 
</table>
1023: 
<?php
1024: 
echo tng_adminfooter();
1025: 
?>
1026: 
1027: 
%fileend:%
1028: 
1029: 
**********************************************************************************
1030: 
*** The language strings are in the 'languages' folder in the standard mod subfolder.
1031: