<?php // This sends emails to the approriate individuals (no keep or remove yet)
  $libraryPath = 'cmsAdmin/lib/viewer_functions.php';
 $dirsToCheck = array('/hsphere/local/home/apbcweb/artistsofpalmbeachcounty.org/','','../','../../','../../../');
  foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

  list($common_informationRecords, $common_informationMetaData) = getRecords(array(
    'tableName'   => 'common_information',
    'allowSearch' => '0',
    'limit'       => '1',
	// 'debugSql' => true, 
  ));
  $common_informationRecord = @$common_informationRecords[0]; // get first record

  ?>
<?php         
list($master_exhibition_listRecords, $master_exhibition_listMetaData) = getRecords(array(
'tableName' => 'master_exhibition_list',

));
?>
<?php   
$numToName = array(); 
foreach ($master_exhibition_listRecords as $record){ 
  $numToName[$record['num']] = $record['title']; 


}
?>
<?php $agree = $CURRENT_USER['allowedFolders'] ?>
<?php 
 $where = ""; 
  ?>
<?php foreach ($master_exhibition_listRecords as $record): ?>
<?php if (strpos($agree, 'exhibition_manager')|| @$CURRENT_USER['isAdmin']): ?>
<?php if (@$CURRENT_USER['for_which_exhibition'] == $record['num']) { $where = $record['title'];}?>
<?php else: ?>
<?php if ($FORM['where'] == $record['num']) { $where = $record['title'];}?>
<?php endif ?>
<?php endforeach; ?>
<?php
 list($exhibition_email_testRecords, $exhibition_email_testMetaData) = getRecords(array(  
    'tableName'   => 'exhibition_email_test',  
    'where'       => " project_title = '$where'",  
	
  ));

?>
<link href="css/apbc900.css" rel="stylesheet" type="text/css" />


<form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">
  <select name="where">
    <option value="">Select</option>
    <?php foreach($numToName as $num => $name): ?>
    <option value="<?php echo $num;?>"><?php echo $name;?></option>
    <?php endforeach?>
  </select>
  <input type="submit" name="submit" value="Select An Exhibition And Click To Send Acceptance E-mails">
</form>
<br />
<div  align="center">
<?php if(!$where):?>
<span class=" heading-text-red">***</span><span class=" heading-text">YOU MUST SELECT AN EXHIBITION TO VIEW THE SUBMISSIONS </span><span class=" heading-text-red">***</span>
<?php endif; ?>
<?php foreach($exhibition_email_testRecords as $record) : ?>
<?php $the_to = $record['email']; ?>
<?php $first_name = $record['first_name'] ; ?>
<?php $last_name = $record['last_name'] ; ?>
<?php ob_start(); // start capturing output ?>
<?php $instructionInformation = array(); ?>
<span class='heading-text-yellow'>CONGRATULATIONS, THESE WORKS WERE ACCEPTED BY THE JURORS FOR INCLUSION INTO THE <?php echo strtoupper($where) ?> EXHIBITION (17).</span><br />
<br />
<?php foreach ($exhibition_email_testRecords as $record): ?>
<?php if($the_to == $record['email']) : ?>
<?php foreach ($record['uploads'] as $upload): ?>
<?php if($upload['info5'] == 0 || !$upload['info5']) : ?>
<img src="http://www.artistsofpalmbeachcounty.org<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>"  /> <br />
<?php // get the instructions for this particular image
        $instructions = mysql_get("email_image_information",null,"file_name = '".$upload['filename']."' AND project_title = '".$record['project_title']."'");
 
        // Get only the instructions we want to show - in this case, the fields we want start with 'complete_'
        foreach ( $instructions as $field => $value ) {
          
          if ( preg_match("/^complete_/",$field) ) {
            
            // Replace all the underscores with spaces and remove 'complete_' from the field name
            // then capitalize all the individual words so we can use this as a proper label
            $field = str_replace("complete_","",$field);
            $field = str_replace("_"," ",$field);
            $field = ucwords($field);
            
            // Add this extra info to the appropriate upload in the exhibition_email_testRecords array
            // in it's own array called 'email_image_information'
            $exhibition_email_testRecord['uploads'][$key]['email_image_information'][$field] = $value;
	    $instructionInformation[$field] = $value;
	    
      } }
  ?>
<?php foreach ( $instructionInformation as $field => $instruction ) : ?>
<?php if ( @$instruction && $field == 'Title') : ?>
<?php // Replace all double quotes with single quotes
					   $instruction = preg_replace("[\"]", "''", $instruction); ?>
<div ><?php echo $field.': '.$instruction; ?></div>
<?php endif; ?>
<?php endforeach; ?>
<?php if (!$upload['info5'] == 1):?><span class='body-text-yellow'>Congratulations, this work has been accepted.</span><?php endif; ?><br />
<br />
<?php endif; ?>
<?php endforeach ?>
<?php endif; ?>
<?php endforeach ?>
<?php $output = ob_get_clean(); // stop capturing output  ?>
<?php ob_start(); // start capturing output2 ?>
<?php $instructionInformation = array(); ?>
<span class='heading-text-yellow'>UNFORTUNATELY THESE WORKS WERE NOT ACCEPTED BY THE JURORS FOR INCLUSION INTO THE <?php echo strtoupper($where) ?> EXHIBITION (17).</span><br />
<br />
<?php foreach ($exhibition_email_testRecords as $record): ?>
<?php if($the_to == $record['email']) : ?>
<?php foreach ($record['uploads'] as $upload): ?>
<?php if($upload['info5'] == 1) : ?>
<img src="http://www.artistsofpalmbeachcounty.org<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>"  /> <br />
<?php // get the instructions for this particular image
        $instructions = mysql_get("email_image_information",null,"file_name = '".$upload['filename']."' AND project_title = '".$record['project_title']."'");
 
        // Get only the instructions we want to show - in this case, the fields we want start with 'complete_'
        foreach ( $instructions as $field => $value ) {
          
          if ( preg_match("/^complete_/",$field) ) {
            
            // Replace all the underscores with spaces and remove 'complete_' from the field name
            // then capitalize all the individual words so we can use this as a proper label
            $field = str_replace("complete_","",$field);
            $field = str_replace("_"," ",$field);
            $field = ucwords($field);
            
            // Add this extra info to the appropriate upload in the exhibition_email_testRecords array
            // in it's own array called 'email_image_information'
            $exhibition_email_testRecord['uploads'][$key]['email_image_information'][$field] = $value;
	    $instructionInformation[$field] = $value;
	    
      } }
  ?>
<?php foreach ( $instructionInformation as $field => $instruction ) : ?>
<?php if ( @$instruction && $field == 'Title') : ?>
<?php // Replace all double quotes with single quotes
					   $instruction = preg_replace("[\"]", "''", $instruction); ?>
<div ><?php echo $field.': '.$instruction; ?></div>
<?php endif; ?>
<?php endforeach; ?>
<?php if ($upload['info5'] == 1):?><span class='body-text-yellow'>Sorry, this work has not been accepted.</span><?php endif; ?>
<br />
<br />
<?php endif; ?>
<?php endforeach ?>
<?php endif; ?>
<?php endforeach ?>
<?php $output2 = ob_get_clean(); // stop capturing output  ?>
<?php
  

 // $the_to = $record['email'];
   $the_from  = "exhibition-submissions@artistsofpalmbeachcounty.org";
$to = "$the_to";
$from = "$the_from";
$headers  = "From: $from\r\n";
    $headers .= "Content-type: text/html\r\n";  

$subject = "Your submission to the $where Exhibition has been Juried";
$message = <<<EOF
<html>
<head>
<style type="text/css">
.body-text {font-family:Arial; font-size: 1.0em;}
.body-text-yellow {font-family:Arial; color: rgb(255,255,0); font-size: 1.0em;}
.heading-text-yellow {font-family:Arial; color: rgb(255,255,0); font-size: 1.3em;}
</style>
</head>
<body bgcolor="#B3B3D3">
<table style='background-color: #7C7164;' width='100%' align='center' border='0' >
			  <tr>
    <td align='left' >
	<table style='background-color: #7C7164;' width='70%' align='center' border='0' >
			  <tr>
    <td align='left' >
 <div align='left'> <img src='http://www.artistsofpalmbeachcounty.org/images/APBC-LOGO.png' width='800' height='183' style='border:hidden'/></div><br /><br />
  <div align='left' class='body-text'>
  Hello $first_name $last_name,
  <br /><br />
 $output<br /><br />$output2

    <br /><br />
  Thank you for submitting your work to this exhibition,
  <br /><br />
 The Exhibition Committee<br />
  Artists of Palm Beach County</div>
  </td>
    </tr>
	</table>
	</td>
    </tr>
	</table>
  </body>
</html>
EOF;
   //end of message 
mail($to,$subject,$message,$headers);

?>
<?php endforeach ?>