<?PHP

require_once 'class.templatepage.php';

class MusiclinkPage extends TemplatePage {
	public function __construct() {
		parent::__construct();
	}

	public function generate() {
		$this->common_title = $this->language( 'title-music' );

		$edit = getInt( 'edit' );
		$music_link_id = getInt( 'music_link_id' );
		$downloaded = getInt( 'downloaded' );

		// Show/edit music_link
		if ( $music_link_id ) {
			$this->write_menu( 'music' );
			$this->add_breadcrumb( $this->language( 'breadcrumb-all-music' ), 'musicsearch' );
			// Load music_link
			if ( $edit ) {
				$this->musicLinkService->clearById( $music_link_id );
			}
			$row = $this->musicLinkService->getById( $music_link_id );
			// Check music_link exists
			if ( $row ) {
				$music_link = new MusicLink( $this, $row );
				// Edit music_link
				if ( $edit ) {
					require 'musiclinks.edit.php';
				} elseif ( $downloaded ) {
					$object = $music_link;
					require 'music.downloaded.php';
				} else {
					// Show music_link
					require 'musiclinks.view.php';
				}
			} else {
				$this->redirect( "{$this->base}/musicsearch" );
			}
		} else {
			$this->redirect( "{$this->base}/musicsearch" );
		}
	}
}
new MusiclinkPage();
