<?php 
 
/************************************************************* 
 
 * This script is developed by Arturs Sosins aka ar2rsawseen, http://webcodingeasy.com 
 
 * Fee free to distribute and modify code, but keep reference to its creator 
 
 *
 
 * This class uses Guitar chord API http://pargitaru.co.cc/api/.
 
 * It can find chord variations based on given data about chord
 
 * You can specify chord name, chord modification, or/and string/fret combination
 
 * 
 
 * For more information, examples and online documentation visit:  
 
 * http://webcodingeasy.com/PHP-classes/Guitar-chord-API-class
 
**************************************************************/
 
//This is an example usage of Guitar Chord API class from http://pargitaru.co.cc/api/
 
//this example generates three forms
 
//First one for searching for standart chords based on chord name and/or modification
 
//Second one for searching for special chords based on chord name
 
//Third one is for searching standart and special chords by specifying string and fret
 
 
include("./chord.php");
 
$chord = new chords();
 
 
//*------using arrays to genereat standart chord form example-----*/
 
if(isset($_POST['from_select']))
 
{
 
    //setting chord name, empty values will be ignored
 
    $chord->set_chord($_POST['chord']);
 
    //setting chord modification, empty values will be ignored
 
    $chord->set_modification($_POST['modf']);
 
    //requesting json data, json is a default data output format, so no need pass it as a parameter(here just for example)
 
    //to get xml data use $chord->request("xml");
 
    $chord_data = json_decode($chord->request("json"), true);
 
    //getting errors
 
    $errors = $chord->get_errors();
 
    //checking if there are any error
 
    if(!empty($errors))
 
    {
 
        foreach($errors as $error)
 
        {
 
            echo "<p>".$error."</p>";
 
        }
 
    }
 
    else
 
    {
 
        foreach($chord_data['chords'] as $ch)
 
        {
 
            echo "<p>".$ch['chord'].$ch['modf'].": ";
 
            foreach($ch as $key => $val)
 
            {
 
                if(!in_array($key, array("chord", "modf")))
 
                {
 
                    echo $val." ";
 
                }
 
            }
 
            echo "</p>";
 
        }
 
    }
 
}
 
echo "<p>Search for chords and modifications:</p>";
 
echo "<form action='' method='post'>";
 
$chord_arr = $chord->get_chords();
 
echo "<select name='chord'>";
 
echo "<option value=''>--</option>";
 
foreach($chord_arr as $val)
 
{
 
    echo "<option value='".$val."'>".$val."</option>";
 
}
 
echo "</select>";
 
$modf_arr = $chord->get_modifications();
 
echo "<select name='modf'>";
 
echo "<option value=''>--</option>";
 
foreach($modf_arr as $val)
 
{
 
    echo "<option value='".$val."'>".$val."</option>";
 
}
 
echo "</select>";
 
echo "<input type='hidden' name='from_select' value='true'/>";
 
echo "<input type='submit' value='Find'/>";
 
echo "</form>";
 
/*-----------------------------------------------------------------------------*/
 
 
//*------using arrays to genereat special chord form example-----*/
 
if(isset($_POST['from_select_sp']))
 
{
 
    //setting chord name, empty values will be ignored
 
    //true specifies that this is a special chord
 
    $chord->set_chord($_POST['chord'], true);
 
    //requesting json data, json is a default data output format
 
    $chord_data = json_decode($chord->request(), true);
 
    //getting errors
 
    $errors = $chord->get_errors();
 
    //checking if there are any error
 
    if(!empty($errors))
 
    {
 
        foreach($errors as $error)
 
        {
 
            echo "<p>".$error."</p>";
 
        }
 
    }
 
    else
 
    {
 
        foreach($chord_data['chords'] as $ch)
 
        {
 
            echo "<p>".$ch['chord'].": ";
 
            foreach($ch as $key => $val)
 
            {
 
                if(!in_array($key, array("chord", "modf")))
 
                {
 
                    echo $val." ";
 
                }
 
            }
 
            echo "</p>";
 
        }
 
    }
 
}
 
echo "<p>Search for special chords:</p>";
 
echo "<form action='' method='post'>";
 
$chord_arr = $chord->get_specials();
 
echo "<select name='chord'>";
 
echo "<option value=''>--</option>";
 
foreach($chord_arr as $val)
 
{
 
    echo "<option value='".$val."'>".$val."</option>";
 
}
 
echo "</select>";
 
echo "<input type='hidden' name='from_select_sp' value='true'/>";
 
echo "<input type='submit' value='Find'/>";
 
echo "</form>";
 
/*-----------------------------------------------------------------------------*/
 
 
//*------Searching for chords by strings and frets-----*/
 
if(isset($_POST['by_string']))
 
{
 
    //setting strings to search for standart chords
 
    $chord->set_strings($_POST['strings']);
 
    //requesting json data, json is a default data
 
    $chord_data = json_decode($chord->request(), true);
 
    //getting errors
 
    $errors = $chord->get_errors();
 
    //checking if there are any error
 
    if(!empty($errors))
 
    {
 
        echo "<p>Standart chord errors:</p>";
 
        foreach($errors as $error)
 
        {
 
            echo "<p>".$error."</p>";
 
        }
 
    }
 
    else
 
    {
 
        echo "<p>Standart chord results:</p>";
 
        foreach($chord_data['chords'] as $ch)
 
        {
 
            echo "<p>".$ch['chord'].$ch['modf'].": ";
 
            foreach($ch as $key => $val)
 
            {
 
                if(!in_array($key, array("chord", "modf")))
 
                {
 
                    echo $val." ";
 
                }
 
            }
 
            echo "</p>";
 
        }
 
    }
 
    
 
    //reset all data to default values
 
    $chord->reset();
 
    
 
    //setting strings to search for special chords
 
    $chord->set_strings($_POST['strings'], true);
 
    //requesting json data, json is a default data 
 
    $chord_data = json_decode($chord->request(), true);
 
    //getting errors
 
    $errors = $chord->get_errors();
 
    //checking if there are any error
 
    if(!empty($errors))
 
    {
 
        echo "<p>Special chord errors:</p>";
 
        foreach($errors as $error)
 
        {
 
            echo "<p>".$error."</p>";
 
        }
 
    }
 
    else
 
    {
 
        echo "<p>Special chord results:</p>";
 
        foreach($chord_data['chords'] as $ch)
 
        {
 
            echo "<p>".$ch['chord'].": ";
 
            foreach($ch as $key => $val)
 
            {
 
                if(!in_array($key, array("chord", "modf")))
 
                {
 
                    echo $val." ";
 
                }
 
            }
 
            echo "</p>";
 
        }
 
    }
 
}
 
echo "<p>Search for chords by frets:</p>";
 
echo "<form action='' method='post'>";
 
$arr = array("e", "b", "g", "D", "A", "E");
 
foreach($arr as $val)
 
{
 
    echo "<p>".$val.": <input type='text' name='strings[]' size='2'/></p>";
 
}
 
echo "<input type='hidden' name='by_string' value='true'/>";
 
echo "<input type='submit' value='Find'/>";
 
echo "</form>";
 
/*-----------------------------------------------------------------------------*/
 
 
    
 
?>
 
 
 |