<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
  /* Manager Aand Admin - All Entrants - Per Exhibition Accepted And Rejected Emails With Break*/
// Included && ($upload['info5'] == '0' || !$upload['info5'] ) for each info field

  // load viewer library
  $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."); }
  if (!$CURRENT_USER) { websiteLogin_redirectToLogin(); }
list($common_informationRecords, $common_informationMetaData) = getRecords(array(
    'tableName'   => 'common_information',
    'limit'       => '1',
 
  ));
  $common_informationRecord = @$common_informationRecords[0]; // get first record
  	
       
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 
 $where = ""; 
  ?>
<?php foreach ($master_exhibition_listRecords as $record): ?>
<?php if (@$FORM['where'] == $record['num']) { $where = $record['title'];}?>
<?php endforeach; ?>
<?php
 list($client_uploadsRecords, $client_uploadsMetaData) = getRecords(array(  
    'tableName'   => 'client_uploads',  
    'where'       => " project_title = '$where'",  
	'orderBy' => 'last_name ASC',

  ));

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta name="robots" content="noindex,nofollow" />
<title>Welcome to the Artists of Palm Beach County - Exhibition Label Spreadheet</title>
<link href="../css/apbc900.css" type="text/css" rel="stylesheet" media="all" />

<!-- This style makes the menu item for the current page white and bold -->
<style type="text/css">
a.contact:link {
	font-family: Verdana;
	color: #ffffff;
	font-size: 0.68em;
	font-weight: bold;
	text-decoration: none;
}
a.contact:visited {
	font-family: Verdana;
	color: #ffffff;
	font-size: 0.68em;
	font-weight: bold;
	text-decoration: none;
}
a.contact:hover {
	font-family: Verdana;
	color: #ffffff;
	font-size: 0.68em;
	font-weight: bold;
	text-decoration: none;
}
a.contact:active {
	font-family: Verdana;
	color: #ffffff;
	font-size: 0.68em;
	font-weight: bold;
	text-decoration: none;
}
</style>
<link rel="stylesheet" type="text/css" href="../css/anylinkcssmenu.css" />
<script type="text/javascript" src="../Scripts/anylinkcssmenu.js">

/***********************************************
* AnyLink CSS Menu script v2.0- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Project Page at http://www.dynamicdrive.com/dynamicindex1/anylinkcss.htm for full source code
***********************************************/

</script>
<script src="../Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type = "text/javascript" src = "cmsAdmin/3rdParty/jquery/jquery1.4.1.js"></script>
</head>

<body bgcolor="#9b97ad">
<?php
    function mobile_detection ()
{
	if (isset($_SERVER['HTTP_X_WAP_PROFILE']) || isset($_SERVER['HTTP_PROFILE']))
		return true;
 if (isset ($_SERVER['HTTP_ACCEPT']))
	{
		$accept = strtolower($_SERVER['HTTP_ACCEPT']);
		if (strpos($accept, 'wap') !== false)
			return true;
	}

	if (isset ($_SERVER['HTTP_USER_AGENT']))
	{
		if (strpos ($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false)
			return true;
			
			if (strpos ($_SERVER['HTTP_USER_AGENT'], 'Android') !== false)
			return true;

		if (strpos ($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false)
			return true;
	}

	return false;
}
    ?>
<table  align="center" width="1085" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td align="left"><?php if (mobile_detection()) : ?>
      <img src="../images/APBC-LOGO.png" width="800" height="183" />
      <?PHP else: ?>
      <script type='text/javascript'>
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0','height','180','width','100%','pluginspage','http://www.macromedia.com/go/getflashplayer','src','../images/masthead','wmode','transparent','quality','best','play','true','movie','../images/masthead' );
</script>
      <noscript>
      <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" height="180" width="100%">
        <param name="movie" value="../images/masthead.swf" />
        <param name="quality" value="best" />
        <param name="play" value="true" />
        <param name="wmode" value="transparent" />
        <embed height="188" pluginspage="http://www.macromedia.com/go/getflashplayer" src="../images/masthead.swf" type="application/x-shockwave-flash" width="100%" wmode="transparent" quality="best" play="true"></embed>
      </object>
      </noscript>
      <?PHP endif ?></td>
  </tr>
</table>
<table align="center" width="1085" border="0" cellspacing="0" cellpadding="20">
  <tr>
    <td valign="top" align="center"   ><div  align="center">
        <?php if($where):?>
        <span class="heading-text-bold">EXHIBITION LABEL SPREADHEET FOR <?php echo strtoupper($where) ?></span>
        <?PHP else: ?>
        <span class=" heading-text-bold">EXHIBITION LABEL SPREADHEETS</span>
        <?php endif; ?>
      </div>
      <br />
      <?php if (@$CURRENT_USER['isAdmin'] || strpos(@$CURRENT_USER['allowedFolders'], 'exhibition_manager')): ?>
      <form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">
        <select name="where">
          <option value="" class="body-text-bold">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 View">
      </form>
      <br />
      <a class="special" href='?action=logoff'>WHEN YOU'RE DONE, CLICK HERE TO LOG OFF</a></td>
  </tr>
</table>
<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 LABEL SPREADSHEETS</span><span class=" heading-text-red">***</span>
  <?php endif; ?>
</div>
<table align="center" width="900" border="0" cellpadding="5" cellspacing="0">
  <tr>
    <td align="left" valign="top"><div align="center"><span class="heading-text-bold">LABEL SPREADSHEET</span> <br />
    
        <?php //Title formating works on first word but not on last.
function RemoveShouting($instruction)
{
 $lower_exceptions = array(
        "to" => "1", "a" => "1", "the" => "1", "and" => "1", "but" => "1", "or" => "1", "for" => "1", "nor" => "1", "of" => "1"
 );
                                     
 $higher_exceptions = array(
        "I" => "1", "II" => "1", "III" => "1", "IV" => "1",
        "V" => "1", "VI" => "1", "VII" => "1", "VIII" => "1",
        "XI" => "1", "X" => "1"
 );

 $words = split(" ", $instruction);
 $newwords = array();

 foreach ($words as $word)
 {
       $firstElement = reset($newwords);
	   $lastElement = end($newwords);
	    
		if (!$higher_exceptions[$word])
                $word = strtolower($word);
        if (!$lower_exceptions[$word] || (!$word == $firstElement) || (!$word == $lastElement) )
                $word = ucfirst($word);
         array_push($newwords, $word);
 
 }
       
 return join(" ", $newwords); 
}
?>
        <?php $count = 0; ?>
        <?php foreach ($client_uploadsRecords as $record): ?>
        <?php foreach ($record['uploads'] as $upload): ?>
        <?php if ( !$upload['info5'] == 1 ):?>
        <?php $count++; ?>
        <?php endif ?>
        <?php endforeach; ?>
        <?php endforeach; ?>
        <span class="heading-text-yellow">There are
        <?php if($count ==0 ):?>
        0
        <?php else :?>
        <?php echo $count ?>
        <?php endif ?>
        accepted submissions to the "<?php echo ucwords($where) ?>" exhibition.</span><br />
        <span class="body-text-bold">Copy the information between the horizontal lines into a text document.<br />
        Rename the file extension as .csv and open in Excel. </span></div>
      <hr align="center" width="300" color="#660033"/>
      <p class="body-text" style="text-align:left" align="left">Artist,Title,Medium,Size,Price,Representation<br />
        <?php foreach($client_uploadsRecords as $record) : ?>
        <?php $first_name = ucwords(strtolower($record['first_name'])) ; ?>
        <?php // Replace all \ with nothing
					   $first_name = preg_replace("[\\\\]", "", $first_name); ?>
        <?php $last_name = ucwords(strtolower($record['last_name'])) ; ?>
        <?php // Replace all \ with nothing
					   $last_name = preg_replace("[\\\\]", "", $last_name); ?>
        <?php $representation = $record['representation_name'] ; ?>
        <?php ob_start(); // start capturing output ?>
        <?php foreach ($record['uploads'] as $upload): ?>
        <?php if($upload['info5'] == 0 || !$upload['info5']) : ?>
        <?php echo $first_name ?> <?php echo $last_name ?>,
        <?php $instructionInformation = array(); ?>
        <?php // get the instructions for this particular image
        $instructions = mysql_get("image_instructions",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 client_uploadsRecords array
            // in it's own array called 'image_instructions'
            $client_uploadsRecord['uploads'][$key]['image_instructions'][$field] = $value;
	    $instructionInformation[$field] = $value;
	    
      } }
  ?>
        <?php foreach ( $instructionInformation as $field => $instruction ) : ?>
        <?php if ( @$instruction && $field == 'Title' && ($upload['info5'] == '0' || !$upload['info5'] )) : ?>
        <?php // Replace all double quotes with single quotes
					   $instruction = preg_replace("[\"]", "''", $instruction); ?>
        <?php // Replace all underscores with dashes
					   $instruction = preg_replace("/[_]/", " - ", $instruction); ?>
        <?php // Replace all commas with nothing
					   $instruction = preg_replace("[,]", "", $instruction); ?>
        <?php echo RemoveShouting($instruction) ?>,
        <?php endif; ?>
        <?php if ( @!$instruction && $field == 'Title' && ($upload['info5'] == '0' || !$upload['info5'] )) : ?>
        ,
        <?php endif; ?>
        <?php if ( @$instruction && $field == 'Medium' && ($upload['info5'] == '0' || !$upload['info5'] )) : ?>
        <?php // Replace all double quotes with single quotes
					   $instruction = preg_replace("[\"]", "''", $instruction); ?>
        <?php // Replace all underscores with dashes
					   $instruction = preg_replace("/[_]/", " - ", $instruction); ?>
        <?php // Replace all commas with nothing
					   $instruction = preg_replace("[,]", "", $instruction); ?>
        <?php echo RemoveShouting($instruction) ?>,
        <?php endif; ?>
        <?php if ( @!$instruction && $field == 'Medium' && ($upload['info5'] == '0' || !$upload['info5'] )) : ?>
        ,
        <?php endif; ?>
        <?php if ( @$instruction && $field == 'Dimensions' && ($upload['info5'] == '0' || !$upload['info5'] )) : ?>
        <?php // Replace all double quotes with single quotes
					   $instruction = preg_replace("[\"]", "''", $instruction); ?>
        <?php // Replace all underscores with dashes
					   $instruction = preg_replace("/[_]/", " - ", $instruction); ?>
        <?php // Replace all commas with nothing
					   $instruction = preg_replace("[,]", "", $instruction); ?>
        <?php echo ucwords(strtolower($instruction)) ?>,
        <?php endif; ?>
        <?php if ( @!$instruction && $field == 'Dimensions' && ($upload['info5'] == '0' || !$upload['info5'] ) ) : ?>
        ,
        <?php endif; ?>
        <?php if (@$instruction && $field == 'Price' && ($upload['info5'] == '0' || !$upload['info5'] )) : ?>
        <?php // Replace all commas with periods
					   $instruction = preg_replace("[,]", ".", $instruction); ?>
        <?php 
	   // Only allow 0-9 and . 
	   $instruction = preg_replace("/[^0-9.]/i", "", $instruction);?>
        <?php if (!$instruction ==""):?>
        $<?php echo $instruction ?>,
        <?php endif; ?>
        <?php endif; ?>
        <?php if ( @!$instruction && $field == 'Price' && ($upload['info5'] == '0' || !$upload['info5'] )) : ?>
        NFS,
        <?php endif; ?>
        <?php endforeach; ?>
        <?php endif; ?>
        <?php if ( $representation && ($upload['info5'] == '0' || !$upload['info5'] )) : ?>
        <?php // Replace all double quotes with single quotes
					   $representation = preg_replace("[\"]", "''", $representation); ?>
        <?php // Replace all underscores with dashes
					   $representation = preg_replace("/[_]/", " - ", $representation); ?>
        <?php // Replace all commas with nothing
					   $representation = preg_replace("[,]", "", $representation); ?>
        Courtesy of: <?php echo $representation ?><br />
        <?php endif; ?>
        <?php if ( @!$representation && ($upload['info5'] == '0' || !$upload['info5'] )) : ?>
        <br />
        <?php endif; ?>
        <?php endforeach ?>
        <?php endforeach ?>
      
      <hr width="300" color="#660033"/></td>
  </tr>
</table>
<p>
  <?php else:?>
  <br />
  <span class="heading-text-yellow">Please log in as an administrator or manager and then return to this page.</span>
  <?php endif; ?>
</p>
<script type="text/javascript">

//anylinkcssmenu.init("menu_anchors_class") //call this function at the very *end* of the document!
anylinkcssmenu.init("anchorclass")

</script>
</body>
</html>