<?php
#
#   Send email to guest editor
#
#   Collect input based upon request
$currentRequest = $_POST['req'];
if ($currentRequest == 'edit') {
    requestEdit();
}
print 'Done';
exit;



#
#   Email editor name (pfn), gallery (gfn), images affected, fields changed (cf).
#   https://isiphotos.photoshelter.com/gallery/Boston-College-vs-Navy-February-27-2018/G0000s2B3Iqe4h68/C00003G38X2EBKyU#
#   Email is HTML.
#
function requestEdit() {
    $currentGallery = $_POST['gfn'];
    $currentGalleryID = $_POST['gid'];
    $currentCollectionID = $_POST['cid'];
    $currentPhotographer = $_POST['p'];
    $currentPhotographerTO = $_POST['pe'];
    $currentPhotographerMSG = $_POST['msg'];
    $currentData = $_POST['data'];
    $currentExpire = $_POST['expire'];

#   Send an email with IPTC edit link to guest editor
    $editorFrom = 'john@isiphotos.com';
    
    $sentStatus = false;
        $MailTo = $currentPhotographerTO;
        $MailFrom = $editorFrom;
        $MailReply= $editorFrom;
        $MailSubject = "Image player name request for gallery: {$currentGallery}";
        $TO = $currentPhotographerTO;
        $HEADERS  = "MIME-Version: 1.0 \r\n";
        $HEADERS .= "Content-type: text/html; charset=iso-8859-1 \r\n";
        $HEADERS .= "From: {$MailFrom}";
        $HEADERS .= "\r\nReply-To: {$MailReply}";
        $SUBJECT = $MailSubject;
        $MESSAGE = " <br>";
        $MESSAGE .= "{$currentPhotographerMSG}<br><br><br>";
        $MESSAGE .= "Link expires: {$currentExpire}<br>";
        $MESSAGE .= "Link:&nbsp;&nbsp;<a href='http://isiphotos.com/iptcedit?data={$currentData}'>Click to edit images</a><br>";
        $MESSAGE .= "<br>";
            
#
#       Close the pipe, sending the email
#
        $sentStatus = mail($TO,$SUBJECT,$MESSAGE,$HEADERS);



    if ($sentStatus) {
        print 'successful' ;
        exit;
    } else {
        print 'fail' ;
        exit;
    }
    print 'done';
    exit;
}
#
#   Log request
#   Update file with date, time GMT, timezone, total images, total time, average time, and photographer
#
function requestLog() {
    $inputData = $_GET['item'];

#   Log entry for the data file.
    $inputData = "{$inputData}\n";
#
#   Append data file with current request/data.
#
    $dataFile = fopen("isi.iptcedit.data.txt", 'a');
    flock($dataFile, LOCK_EX);
    fwrite ($dataFile, $inputData);
    flock($dataFile, LOCK_UN);
    fclose ($dataFile);

    print 'done';
#   print $inputData;
    exit;
}



?>