Access Denied
You do not have access to this resource.');
//-- display messages as to why the editing access was denied
if (!WT_USER_CAN_EDIT) print "
".i18n::translate('This user name cannot edit this GEDCOM.');
if (!$ALLOW_EDIT_GEDCOM) print "
".i18n::translate('Editing this GEDCOM has been disabled by the administrator.');
if (!$disp) {
print "
".i18n::translate('Privacy settings prevent you from editing this record.');
if (!empty($pid)) print "
".i18n::translate('You have no access to')." pid $pid.";
}
print "
\n";
print_simple_footer();
exit;
}
if ($ENABLE_AUTOCOMPLETE) require WT_ROOT.'/js/autocomplete.js.htm';
echo WT_JS_START;
?>
// Shared Notes =========================
function findnote(field) {
pastefield = field;
findwin = window.open('find.php?type=note', '_blank', 'left=50, top=50, width=600, height=520, resizable=1, scrollbars=1');
return false;
}
var language_filter, magnify;
var pastefield;
language_filter = "";
magnify = "";
function openerpasteid(id) {
window.opener.paste_id(id);
window.close();
}
function paste_id(value) {
pastefield.value = value;
}
function paste_char(value, lang, mag) {
pastefield.value += value;
language_filter = lang;
magnify = mag;
}
function checkpath(folder) {
value = folder.value;
if (value.substr(value.length-1, 1) == "/") value = value.substr(0, value.length-1);
if (value.substr(0, 1) == "/") value = value.substr(1, value.length-1);
result = value.split("/");
if (result.length > ) {
alert('');
folder.focus();
return false;
}
}
";
} else {
if (!move_uploaded_file($_FILES["mediafile"]["tmp_name"], filename_decode($newFile))) {
// the file cannot be copied
$error .= i18n::translate('There was an error uploading your file.')."
".file_upload_error_text($_FILES["mediafile"]["error"])."
";
} else {
@chmod(filename_decode($newFile), WT_PERM_FILE);
AddToLog("Media file {$folderName}{$mediaFile} uploaded", 'media');
}
}
}
if ($error=="" && !empty($_FILES["thumbnail"]["name"])) {
$newThum = $realThumbFolderName.$mediaFile;
// Copy user-supplied thumbnail file into the destination directory
if (file_exists(filename_decode($newThum))) {
$error .= i18n::translate('Media thumbnail already exists.')." ".$newThum."
";
} else {
if (!move_uploaded_file($_FILES["thumbnail"]["tmp_name"], filename_decode($newThum))) {
// the file cannot be copied
$error .= i18n::translate('There was an error uploading your file.')."
".file_upload_error_text($_FILES["thumbnail"]["error"])."
";
} else {
@chmod(filename_decode($newThum), WT_PERM_FILE);
AddToLog("Media file {$thumbFolderName}{$mediaFile} uploaded", 'media');
}
}
}
if ($error=="" && empty($_FILES["mediafile"]["name"]) && !empty($_FILES["thumbnail"]["name"])) {
// Copy user-supplied thumbnail file into the main destination directory
if (!copy(filename_decode($whichFile1), filename_decode($whichFile2))) {
// the file cannot be copied
$error .= i18n::translate('There was an error uploading your file.')."
".i18n::translate('The file %s could not be copied from %s', $realThumbFolderName.$mediaFile, $realThumbFolderName.$mediaFile)."
";
} else {
@chmod(filename_decode($whichFile2), WT_PERM_FILE);
AddToLog("Media file {$folderName}{$mediaFile} copied from {$thumbFolderName}{$mediaFile}", 'media');
}
}
if ($error=="" && !empty($_FILES["mediafile"]["name"]) && empty($_FILES["thumbnail"]["name"])) {
if (safe_POST('genthumb', 'yes', 'no') == 'yes') {
// Generate thumbnail from main image
$parts = pathinfo_utf($mediaFile);
if (!empty($parts["extension"])) {
$ext = strtolower($parts["extension"]);
if (isImageTypeSupported($ext)) {
$thumbnail = $thumbFolderName.$mediaFile;
$okThumb = generate_thumbnail($folderName.$mediaFile, $thumbnail, "OVERWRITE");
if (!$okThumb) {
$error .= i18n::translate('Thumbnail %s could not be generated automatically.', $thumbnail);
} else {
echo i18n::translate('Thumbnail %s generated automatically.', $thumbnail);
print "
";
AddToLog("Media thumbnail {$thumbnail} generated", 'media');
}
}
}
}
}
// Let's see if there are any errors generated and print it
if (!empty($error)) {
echo '', $error, "
\n";
$mediaFile = "";
$finalResult = false;
} else $finalResult = true;
}
if ($mediaFile=="") {
// No upload: should be an existing file on server
if ($tag[0]=="FILE") {
if (!empty($text[0])) {
$isExternal = isFileExternal($text[0]);
if ($isExternal) {
$fileName = $text[0];
$mediaFile = $fileName;
$folderName = "";
} else {
$fileName = check_media_depth($text[0], "BACK");
$mediaFile = basename($fileName);
$folderName = dirname($fileName)."/";
}
}
if ($mediaFile=="") {
echo '', i18n::translate('Blank name or illegal characters in name'), "
\n";
$finalResult = false;
} else $finalResult = true;
} else {
//-- check if the file is used in more than one gedcom
//-- do not allow it to be moved or renamed if it is
$myFile = str_replace($MEDIA_DIRECTORY, "", $oldFolder.$oldFilename);
$multi_gedcom=is_media_used_in_other_gedcom($myFile, WT_GED_ID);
// Handle Admin request to rename or move media file
if ($filename!=$oldFilename) {
$parts = pathinfo_utf($filename);
if (empty($parts["extension"]) || !in_array(strtolower($parts["extension"]), $MEDIATYPE)) {
$parts = pathinfo_utf($oldFilename);
$filename .= ".".$parts["extension"];
}
}
if (substr($folder, -1)!="/") $folder .= "/";
if ($folder=="/") $folder = "";
$folder = check_media_depth($folder."y.z", "BACK");
$folder = dirname($folder)."/";
if (substr($oldFolder, -1)!="/") $oldFolder .= "/";
if ($oldFolder=="/") $oldFolder = "";
$oldFolder = check_media_depth($oldFolder."y.z", "BACK");
$oldFolder = dirname($oldFolder)."/";
$_SESSION["upload_folder"] = $folder; // store standard media folder in session
$finalResult = true;
if ($filename!=$oldFilename || $folder!=$oldFolder) {
if ($multi_gedcom) {
echo '', i18n::translate('This file is linked to another genealogical database on this server. It cannot be deleted, moved, or renamed until these links have been removed.'), '
';
if ($filename!=$oldFilename) print i18n::translate('Media file could not be moved or renamed.');
else print i18n::translate('Media file could not be moved.');
print "
";
$finalResult = false;
} else {
$oldMainFile = $oldFolder.$oldFilename;
$newMainFile = $folder.$filename;
$oldThumFile = str_replace($MEDIA_DIRECTORY, $MEDIA_DIRECTORY."thumbs/", $oldMainFile);
$newThumFile = str_replace($MEDIA_DIRECTORY, $MEDIA_DIRECTORY."thumbs/", $newMainFile);
if (media_exists($oldMainFile) == 3) {
// the file is in the media firewall directory
$oldMainFile = get_media_firewall_path($oldMainFile);
$newMainFile = get_media_firewall_path($newMainFile);
}
if (media_exists($oldThumFile) == 3) {
$oldThumFile = get_media_firewall_path($oldThumFile);
$newThumFile = get_media_firewall_path($newThumFile);
}
$isMain = file_exists(filename_decode($oldMainFile));
$okMain = !file_exists(filename_decode($newMainFile));
$isThum = file_exists(filename_decode($oldThumFile));
$okThum = !file_exists(filename_decode($newThumFile));
if ($okMain && $okThum) {
// make sure the directories exist before moving the files
mkdirs(dirname($newMainFile)."/");
mkdirs(dirname($newThumFile)."/");
if ($isMain) $okMain = @rename(filename_decode($oldMainFile), filename_decode($newMainFile));
if ($isThum) $okThum = @rename(filename_decode($oldThumFile), filename_decode($newThumFile));
}
// Build text to tell Admin about the success or failure of the requested operation
$mediaAction = 0;
if ($filename!=$oldFilename) $mediaAction = 1;
if ($folder!=$oldFolder) $mediaAction = $mediaAction + 2;
if (!$isMain) {
echo i18n::translate('Main media file %s%s does not exist.', $oldFolder, $oldFilename);
} else {
if ($okMain) {
switch ($mediaAction) {
case 1:
echo i18n::translate('Main media file %s successfully renamed to %s.', $oldFilename, $filename);
break;
case 2:
echo i18n::translate('Main media file %s successfully moved from %s to %s.', $oldFilename, $oldFolder, $folder);
break;
case 3:
echo i18n::translate('Main media file successfully moved and renamed from %s%s to %s%s.', $oldFolder, $oldFilename, $folder, $filename);
break;
}
} else {
$finalResult = false;
echo '';
switch ($mediaAction) {
case 1:
echo i18n::translate('Main media file %s could not be renamed to %s.', $oldFilename, $filename);
break;
case 2:
echo i18n::translate('Main media file %s could not be moved from %s to %s.', $oldFilename, $oldFolder, $folder);
break;
case 3:
echo i18n::translate('Main media file could not be moved and renamed from %s%s to %s%s.', $oldFolder, $oldFilename, $folder, $filename);
break;
}
echo '';
}
}
print "
";
if (!$isThum) {
echo i18n::translate('Thumbnail file %s%s does not exist.', $oldFolder, $oldFilename);
} else {
if ($okThum) {
switch ($mediaAction) {
case 1:
echo i18n::translate('Thumbnail file %s successfully renamed to %s.', $oldFilename, $filename);
break;
case 2:
echo i18n::translate('Thumbnail file %s successfully moved from %s to %s.', $oldFilename, str_replace($MEDIA_DIRECTORY, $MEDIA_DIRECTORY."thumbs/", $oldFolder), str_replace($MEDIA_DIRECTORY, $MEDIA_DIRECTORY."thumbs/", $folder));
break;
case 3:
echo i18n::translate('Thumbnail file successfully moved and renamed from %s%s to %s%s.', str_replace($MEDIA_DIRECTORY, $MEDIA_DIRECTORY."thumbs/", $oldFolder), $oldFilename, str_replace($MEDIA_DIRECTORY, $MEDIA_DIRECTORY."thumbs/", $folder), $filename);
break;
}
} else {
$finalResult = false;
echo '';
switch ($mediaAction) {
case 1:
echo i18n::translate('Main media file %s could not be renamed to %s.', $oldFilename, $filename);
break;
case 2:
echo i18n::translate('Main media file %s could not be moved from %s to %s.', $oldFilename, str_replace($MEDIA_DIRECTORY, $MEDIA_DIRECTORY."thumbs/", $oldFolder), str_replace($MEDIA_DIRECTORY, $MEDIA_DIRECTORY."thumbs/", $folder));
break;
case 3:
echo i18n::translate('Main media file could not be moved and renamed from %s%s to %s%s.', str_replace($MEDIA_DIRECTORY, $MEDIA_DIRECTORY."thumbs/", $oldFolder), $oldFilename, str_replace($MEDIA_DIRECTORY, $MEDIA_DIRECTORY."thumbs/", $folder), $filename);
break;
}
echo '';
}
}
print "
";
}
}
// Insert the 1 FILE xxx record into the arrays used by function handle_updates()
$glevels = array_merge(array("1"), $glevels);
$tag = array_merge(array("FILE"), $tag);
$islink = array_merge(array(0), $islink);
$text = array_merge(array($folder.$filename), $text);
$mediaFile = $filename;
$folderName = $folder;
}
}
if ($finalResult && $mediaFile!="") {
// NOTE: Build the gedcom record
// NOTE: Level 0
$media_id = get_new_xref("OBJE");
$newged = "0 @".$media_id."@ OBJE\n";
//-- set the FILE text to the correct file location in the standard media directory
if (WT_USER_GEDCOM_ADMIN) $text[0] = $folderName.$mediaFile;
else $newged .= "1 FILE ".$folderName.$mediaFile."\n";
$newged = handle_updates($newged);
require_once WT_ROOT.'includes/classes/class_media.php';
$media_obje = new Media($newged);
$mediaid = Media::in_obje_list($media_obje);
if (!$mediaid) $mediaid = append_gedrec($newged, WT_GED_ID);
if ($mediaid) {
AddToChangeLog("Media ID ".$mediaid." successfully added.");
if ($linktoid!="") $link = linkMedia($mediaid, $linktoid, $level);
else $link = false;
if ($link) {
AddToChangeLog("Media ID ".$media_id." successfully added to $linktoid.");
} else {
echo "", i18n::translate('Paste the following ID into your editing fields to reference the newly created record '), " $mediaid
\n";
echo WT_JS_START;
echo "openerpasteid('", $mediaid, "');";
echo WT_JS_END;
}
}
print i18n::translate('Update successful');
}
}
// **** end action "newentry"
// **** begin action "update"
if ($action == "update") {
if (empty($level)) $level = 1;
//-- check if the file is used in more than one gedcom
//-- do not allow it to be moved or renamed if it is
$myFile = str_replace($MEDIA_DIRECTORY, "", $oldFolder.$oldFilename);
$multi_gedcom=is_media_used_in_other_gedcom($myFile, WT_GED_ID);
$isExternal = isFileExternal($oldFilename) || isFileExternal($filename);
$finalResult = true;
// Handle Admin request to rename or move media file
if (!$isExternal) {
if ($filename!=$oldFilename) {
$parts = pathinfo_utf($filename);
if (empty($parts["extension"]) || !in_array(strtolower($parts["extension"]), $MEDIATYPE)) {
$parts = pathinfo_utf($oldFilename);
$filename .= ".".$parts["extension"];
}
}
if (!isset($folder) && isset($oldFolder)) $folder = $oldFolder;
$folder = trim($folder);
if (substr($folder, -1)!="/") $folder .= "/";
if ($folder=="/") $folder = "";
$folder = check_media_depth($folder."y.z", "BACK");
$folder = dirname($folder)."/";
if (substr($oldFolder, -1)!="/") $oldFolder .= "/";
if ($oldFolder=="/") $oldFolder = "";
$oldFolder = check_media_depth($oldFolder."y.z", "BACK");
$oldFolder = dirname($oldFolder)."/";
}
if ($filename!=$oldFilename || $folder!=$oldFolder) {
if ($multi_gedcom) {
echo '', i18n::translate('This file is linked to another genealogical database on this server. It cannot be deleted, moved, or renamed until these links have been removed.'), '
';
if ($filename!=$oldFilename) print i18n::translate('Media file could not be moved or renamed.');
else print i18n::translate('Media file could not be moved.');
print "
";
$finalResult = false;
} else if (!$isExternal) {
$oldMainFile = $oldFolder.$oldFilename;
$newMainFile = $folder.$filename;
$oldThumFile = str_replace($MEDIA_DIRECTORY, $MEDIA_DIRECTORY."thumbs/", $oldMainFile);
$newThumFile = str_replace($MEDIA_DIRECTORY, $MEDIA_DIRECTORY."thumbs/", $newMainFile);
if (media_exists($oldMainFile) == 3) {
// the file is in the media firewall directory
$oldMainFile = get_media_firewall_path($oldMainFile);
$newMainFile = get_media_firewall_path($newMainFile);
}
if (media_exists($oldThumFile) == 3) {
$oldThumFile = get_media_firewall_path($oldThumFile);
$newThumFile = get_media_firewall_path($newThumFile);
}
$isMain = file_exists(filename_decode($oldMainFile));
$okMain = !file_exists(filename_decode($newMainFile));
$isThum = file_exists(filename_decode($oldThumFile));
$okThum = !file_exists(filename_decode($newThumFile));
if ($okMain && $okThum) {
// make sure the directories exist before moving the files
mkdirs(dirname($newMainFile)."/");
mkdirs(dirname($newThumFile)."/");
if ($isMain) $okMain = @rename(filename_decode($oldMainFile), filename_decode($newMainFile));
if ($isThum) $okThum = @rename(filename_decode($oldThumFile), filename_decode($newThumFile));
}
// Build text to tell Admin about the success or failure of the requested operation
$mediaAction = 0;
if ($filename!=$oldFilename) $mediaAction = 1;
if ($folder!=$oldFolder) $mediaAction = $mediaAction + 2;
if (!$isMain) {
echo i18n::translate('Main media file %s%s does not exist.', $oldFolder, $oldFilename);
} else {
if ($okMain) {
switch ($mediaAction) {
case 1:
echo i18n::translate('Main media file %s successfully renamed to %s.', $oldFilename, $filename);
break;
case 2:
echo i18n::translate('Main media file %s successfully moved from %s to %s.', $oldFilename, $oldFolder, $folder);
break;
case 3:
echo i18n::translate('Main media file successfully moved and renamed from %s%s to %s%s.', $oldFolder, $oldFilename, $folder, $filename);
break;
}
} else {
$finalResult = false;
echo '';
switch ($mediaAction) {
case 1:
echo i18n::translate('Main media file %s could not be renamed to %s.', $oldFilename, $filename);
break;
case 2:
echo i18n::translate('Main media file %s could not be moved from %s to %s.', $oldFilename, $oldFolder, $folder);
break;
case 3:
echo i18n::translate('Main media file could not be moved and renamed from %s%s to %s%s.', $oldFolder, $oldFilename, $folder, $filename);
break;
}
echo '';
}
}
print "
";
if (!$isThum) {
echo i18n::translate('Thumbnail file %s%s does not exist.', str_replace($MEDIA_DIRECTORY, $MEDIA_DIRECTORY."thumbs/", $oldFolder), $oldFilename);
} else {
if ($okThum) {
switch ($mediaAction) {
case 1:
echo i18n::translate('Thumbnail file %s successfully renamed to %s.', $oldFilename, $filename);
break;
case 2:
echo i18n::translate('Thumbnail file %s successfully moved from %s to %s.', $oldFilename, str_replace($MEDIA_DIRECTORY, $MEDIA_DIRECTORY."thumbs/", $oldFolder), str_replace($MEDIA_DIRECTORY, $MEDIA_DIRECTORY."thumbs/", $folder));
break;
case 3:
echo i18n::translate('Thumbnail file successfully moved and renamed from %s%s to %s%s.', str_replace($MEDIA_DIRECTORY, $MEDIA_DIRECTORY."thumbs/", $oldFolder), $oldFilename, str_replace($MEDIA_DIRECTORY, $MEDIA_DIRECTORY."thumbs/", $folder), $filename);
break;
}
} else {
$finalResult = false;
echo '';
switch ($mediaAction) {
case 1:
echo i18n::translate('Main media file %s could not be renamed to %s.', $oldFilename, $filename);
break;
case 2:
echo i18n::translate('Main media file %s could not be moved from %s to %s.', $oldFileName, str_replace($MEDIA_DIRECTORY, $MEDIA_DIRECTORY."thumbs/", $oldFolder), str_replace($MEDIA_DIRECTORY, $MEDIA_DIRECTORY."thumbs/", $folder));
break;
case 3:
echo i18n::translate('Main media file could not be moved and renamed from %s%s to %s%s.', str_replace($MEDIA_DIRECTORY, $MEDIA_DIRECTORY."thumbs/", $oldFolder), $oldFilename, str_replace($MEDIA_DIRECTORY, $MEDIA_DIRECTORY."thumbs/", $folder), $filename);
break;
}
echo '';
}
}
print "
";
}
}
if ($finalResult) {
$_SESSION["upload_folder"] = $folder; // store standard media folder in session
// Insert the 1 FILE xxx record into the arrays used by function handle_updates()
$glevels = array_merge(array("1"), $glevels);
$tag = array_merge(array("FILE"), $tag);
$islink = array_merge(array(0), $islink);
$text = array_merge(array($folder.$filename), $text);
if (!empty($pid)) {
$gedrec=find_gedcom_record($pid, WT_GED_ID, true);
}
$newrec = "0 @$pid@ OBJE\n";
$newrec = handle_updates($newrec);
if (!$update_CHAN) {
$newrec .= get_sub_record(1, "1 CHAN", $gedrec);
}
//print("[".$newrec."]");
//-- look for the old record media in the file
//-- if the old media record does not exist that means it was
//-- generated at import and we need to append it
replace_gedrec($pid, WT_GED_ID, $newrec, $update_CHAN);
if ($pid && $linktoid!="") {
$link = linkMedia($pid, $linktoid, $level);
if ($link) {
AddToChangeLog("Media ID ".$pid." successfully added to $linktoid.");
}
}
}
if ($finalResult) print i18n::translate('Update successful');
}
// **** end action "update"
// **** begin action "delete"
if ($action=="delete") {
if (delete_gedrec($pid, WT_GED_ID)) {
AddToChangeLog("Media ID ".$pid." successfully deleted.");
print i18n::translate('Update successful');
}
}
// **** end action "delete"
// **** begin action "showmediaform"
if ($action=="showmediaform") {
if (!isset($pid)) $pid = "";
if (empty($level)) $level = 1;
if (!isset($linktoid)) $linktoid = "";
show_media_form($pid, "newentry", $filename, $linktoid, $level);
}
// **** end action "showmediaform"
// **** begin action "editmedia"
if ($action=="editmedia") {
if (!isset($pid)) $pid = "";
if (empty($level)) $level = 1;
show_media_form($pid, "update", $filename, $linktoid, $level);
}
// **** end action "editmedia"
print "
";
print "\n";
print "
";
print_simple_footer();
?>