<?php
// WARNING: This script is for educational purposes only. Use of it in any form comes with your express knowledge that you are personally responsible for your actions.

require_once("header.php"); // NOT REQUIRED FOR FUNCTIONALITY
require_once("ciTMS.h.php");

if (
$_POST['artist'] == "" && $_POST['album'] == "" && $_POST['song'] == "")
{
    
$error 'Please enter a search query.';
    
$url '';
}
else
{
    
$artist $_POST['artist'];
    
$album $_POST['album'];
    
$song $_POST['song'];
    
$url 'phobos.apple.com/WebObjects/MZSearch.woa/wa/advancedSearchResults?artistTerm='.$artist.'&songTerm='.$song.'&albumTerm='.$album;
}

?>
<html>
<body>
<div align="center">
    <h3>iTunes Music Store Search</h3>
    <font size="2">[ <a href="./">Home</a> ][ <a href="./itunes-search.phps">Source</a> ]</font><p>
    <form id="form" name="form" action="<?=$_SERVER['PHP_SELF']?>" method="post">
        Artist:
        <input type="text" name="artist" id="artist" size=50 maxlength=200 value="<?=$artist?>"><br />
        Album:
                <input type="text" name="album" id="artist" size=50 maxlength=200 value="<?=$album?>"><br />
        Song:
                <input type="text" name="song" id="artist" size=50 maxlength=200 value="<?=$song?>"><br />
        <input type="submit" value="submit">
    </form><hr>
<?php

if (isset($error)) error($error);

$itms = new ciTMS;

$songs $itms->getResultArray($url);

if (!
is_array($songs)) {
    
error('Your search returned no results');
}

$results=array();

foreach (
$songs as $key=>$val)
{
    if (!isset(
$results[$val['playlistId']])) $results[$val['playlistId']] = array();
    
$results[$val['playlistId']][$val['trackNumber']] = $val;
}

$i=0;
$row=1;

foreach (
$results as $key=>$val)
{
    echo 
'<a href="'.$itms->GetArt($key,$val[1]['s'],true).'"><img src="'.$itms->GetArt($key,$val[1]['s'],false).'" border="0" alt="'.$val[1]['artistName'].' - '.$val[1]['playlistName'].'" title="'.$val[1]['artistName'].' - '.$val[1]['playlistName'].'"></a>'."\n";
    
$i++;
    if ((
$row*5)<=$i)
    {
        echo 
'<br>';
        
$row++;
    }
}

echo 
'<p><font size="1">Modified from <a href="http://www.s-seven.net/blog/">s-seven.net</a> by <a href="http://tpemble.urfbownd.net/itunes/">Tristan</a></font></div></body></html>';


function 
error($error)
{
    echo 
$error.'<p><font size="1">Modified from <a href="http://www.s-seven.net/blog/">s-seven.net</a> by <a href="http://tpemble.urfbownd.net/itunes/">Tristan</a></font></div></body></html>';
    exit;
}

?>