<?php
/*
*********************************************************************
* File          : $RCSfile: scores.php,v $
* Version	: $Revision: 1.3 $
* Modified by	: $Author: jb $ ($Date: 2003/06/28 22:20:19 $)
*********************************************************************
    Classe Cadre
    V 0.01 : NADAL Jean-Baptiste  : 16 02 2014
			 Creation 
*/

class Scores {
		
        // =====================================================
        //                    Les Variables
        var $mScorePath;       	   // chemin de la racine des scores
		var $mName;   		       // Name

        // =============================================================
        // Constructeur de la classe
        function Scores($aPath, $Name)
        {
            $this->mScorePath = $aPath;
        } // fin du constructeur
		
	   	
        // =============================================================
        // Affiche les partitions
        function Affiche ($scoreID)
        {
          if ($scoreID == "") {
          	
          	// Display the root of the scores.
            $this->AfficheRoot();
          }
          else {
          	$this->AfficheScore($scoreID);
          }
        }
        
        
        // =============================================================
        // Affiche la list des partitions
        function AfficheRoot()
        {
           	global $sql_bdd;
			global $table_repertoire;
			global $page_index, $racine;

			$pMonCadre = new Cadre($mName, "", "");
			$pMonCadre->affiche_CadreHaut(true);

   			/* On se connecte sur la base */
   			$connect_db = jb_sql_connect(false);
			$cpt = 0;
        	//$theDirectory = opendir($this->mScorePath);
			// row 0: id
			// row 1: numero
			// row 2: nom
			// row 3: compo
			// row 4: style
			$theDirectory = scandir($this->mScorePath);
			sort($theDirectory);
        	echo "<center><table border=0 width=\"95%\">
           			<tr>
                                <th bgcolor=\"#d5dee6\"> numero </th>
              			<th bgcolor=\"#d5dee6\"> Compositeur </th>
              			<th bgcolor=\"#d5dee6\">  Nom </th>
           			</tr>\n";
           	
			foreach ($theDirectory as $entryName) {	
            	if (($entryName != ".")  && ($entryName != "..")) {
					
					if (($cpt % 3) == 0)
         				echo "<tr bgcolor=\"#DDDDDD\">\n";
      				else
         				echo "<tr bgcolor=\"#CCCCCC\">\n";
                	                 	 
                	$resultat = mysql_db_query($sql_bdd, "select * from $table_repertoire".
                              " where numero=$entryName", $connect_db);
                    $row = mysql_fetch_row($resultat);
					echo "<td>$row[1]</td>".
					     "<td>$row[3]</td>".
                         "<td><a href=$racine/$page_index?page=scores&id=$entryName>".
                         "$row[2]</a></td>\n";
                    $cpt++;
            	}
           	}
           	
           	MYSQL_CLOSE;
   			echo "</table></center><br><br><br>\n";
           	
    		$pMonCadre->affiche_CadreBas(true);          
        }
        
        // =============================================================
        // Affiche toutes les partitions pour un morceau
        function AfficheScore($aScoreID)
        {
        	global $sql_bdd;
			global $table_repertoire;
			global $racine;
			
			$connect_db = jb_sql_connect(false);	
			$resultat = mysql_db_query($sql_bdd, "select * from $table_repertoire".
                              " where numero=$aScoreID", $connect_db);
            $row = mysql_fetch_row($resultat);
			
			$pMonCadre = new Cadre($row[3]." - ".$row[2], "", "");
			$pMonCadre->affiche_CadreHaut(true);
			$theScorePath = $this->mScorePath . $aScoreID;
			$theDirectory = opendir($theScorePath);
			while ($entryName = readdir ($theDirectory)) {
				
            	if (($entryName != ".")  && ($entryName != "..")) {
            		
            		echo $this->GetTitre ($this->GetEntryName ($entryName));
            		echo "<center><table width =\"30%\" border=\"1\">\n";
            		$thePartitionDir = opendir($theScorePath . "/" . $entryName);
            		while ($theNum = readdir ($thePartitionDir)) {
            		    if (($theNum != ".")  && ($theNum != "..")) {
            				$thePageDir = opendir($theScorePath . "/" . $entryName . "/" . $theNum);
            				$theNumString = $theNum;
            				while ($thePage = readdir ($thePageDir)) {
            					if (($thePage != ".")  && ($thePage != "..")) {
            					
            						$theName = substr($thePage, 0, strpos($thePage, '.'));
            						echo "<tr><td>$theNumString</td><td align=\"center\">".
            							"<a href=$racine/$theScorePath" . "/" . $entryName . "/" . $theNum ."/". $thePage . ">".
            							"$theName</a></td></tr>";
            						$theNumString = "";
            					}
            				}
            				closedir ($thePageDir);
            			}
            		}
            		closedir($thePartitionDir);
            		echo "</table></center><br />\n";
            	}
            }
			
			closedir($theDirectory);
			MYSQL_CLOSE;
			$pMonCadre->affiche_CadreBas(true); 
        }
        
        function GetTitre ($aName)
        {
        	return "<table width=\"50%\" bgcolor=\"#5a69a4\" cellpadding=\"0\" cellspacing=\"0\"\n". 
                	"border=\"0\"><tr><td>\n".
            		"<table width=\"100%\" cellpadding=\"3\" cellspacing=\"2\" border=\"0\" >\n".
            		"<tr>\n".
            		"<td bgcolor=\"#5b8cc1\" align=\"left\"><font color=\"white\" size=\"2\">\n".
            		"<b> $aName </b></font><br /></td>\n".
            		"</tr></table>\n</td></tr></table><br />\n";
        }
        
        function GetEntryName ($aName)
		{
			if ($aName == "cla") return "Clarinette";
			else if ($aName == "flu") return "Flute";
			else if ($aName == "trb") return "Trombone";
			else if ($aName == "pic") return "Piccolo";
			else if ($aName == "per") return "Percussions";
			else if ($aName == "htb") return "Hautbois";		
			else if ($aName == "trp") return "Trompette";
			else if ($aName == "dir") return "Direction";
			else if ($aName == "sax") return "Sax Alto";
			else if ($aName == "sat") return "Sax T&eacute;nor";
			else if ($aName == "sab") return "Sax Baryton";
			else if ($aName == "cor") return "Cor";			
			else if ($aName == "eup") return "Euphonium";			
			else if ($aName == "bas") return "Basson";
			else if ($aName == "cba") return "Contrebasse";
                        else if ($aName == "crn") return "Cornet";			
                        else if ($aName == "coa") return "Cor Anglais";
                        else if ($aName == "clb") return "Clarinette Basse";
                        else if ($aName == "har") return "Harpe";
                        else if ($aName == "pia") return "Piano";
                        else if ($aName == "tub") return "Tuba";
                        else if ($aName == "sup") return "Parties supplementaires";
                        else if ($aName == "par") return "Parties";
			else return $aName;
		}
};

?>
