<?php //This lists the approriate images and image information
  $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'",  
	
  ));

?>

<form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">
  <select name="where">
    <option value=""><span class="body-text-bold">Select</span></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 View">
</form>
<br />
<div  align="center">
<?php if(!$where):?>
<span class=" heading-text-red">***</span><span class=" heading-text-yellow">YOU MUST SELECT AN EXHIBITION TO VIEW THE SUBMISSIONS </span><span class=" heading-text-red">***</span>
<?php endif; ?>
<table align="center" width="1300" border="0" cellspacing="0" cellpadding="20">
  <tr>
    <td valign="top" align="center" bgcolor="#7C7164"  ><?php $instructionInformation = array(); ?>
      <?php foreach ($exhibition_email_testRecords as $record): ?>
      <?php foreach ($record['uploads'] as $upload): ?>
      <?php $recordnumber = $upload["recordNum"] ?>
      <?php if($upload['info5'] == "1") : ?>
      <img src="<?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; ?>
      Keep: <?php echo $upload['info5'] ?><br />
      Image Number: <?php echo $upload['num'] ?><br />
      Record Number: <?php echo $record['num'] ?><br />
      Exhibitor Number: <?php echo $record['createdByUserNum'] ?><br />
      Submitted By: <?php echo $record['first_name'] ?> <?php echo $record['last_name'] ?><br />
      Email: <?php echo $record['email'] ?><br />
      Filename: <?php echo $upload['filename'] ?><br />
      <?php endif; ?>
      <?php endforeach ?>
      <?php endforeach ?></td>
  </tr>
</table>
