<?php


	$pr = 20; // $this->paginator->getPageRange();
	$p  = $this->paginator->getCurrentPageNumber();
	$c  = $this->paginator->getCurrentItemCount();
	$total= $this->paginator->getTotalItemCount();

	$from = 1 + $pr * ($p - 1);
	$to = $from -1  + $c;

	// Zend_Debug::dump($pr , 'getPageRange');
	// Zend_Debug::dump($p , 'getCurrentPageNumber');
	// Zend_Debug::dump($c , 'getCurrentItemCount');
	// Zend_Debug::dump($total, 'getTotalItemCount');

	if( $to > $total ) $to = $total;

	switch( $this->params['type'] ){
		case 'cd' :
			$title = "Catalogue CD";
			$searchLabel = "Recherche de CD";
			$length_icon = 'fa fa-clock';
			$length_title = 'Durée';
			$url_route = 'biblio-cd';
			break;
		case 'cassette' :
			$title = "Catalogue de Cassettes Audio";
			$searchLabel = "Recherche de Cassettes Audio";
			$length_icon = 'fa fa-clock';
			$length_title = 'Durée';
			$url_route = 'biblio-cassette';
			//$lenght_icon = 'fa fa-simplybuilt';
			break;
		case 'braille' :
			$title = "Catalogue de livres brailles";
			$searchLabel = "Recherche de livres brailles";
			$length_icon = 'fa fa-book';
			$length_title = 'Durée';
			$url_route = 'biblio-braille';
			break;
		case 'book':
		default:
			$title = "Catalogue de livres Grand Caractères";
			$searchLabel = "Recherche de livres Grand Caractères";
			$length_icon = 'fa fa-book';
			$length_title = 'Durée';
			$url_route = 'biblio-cd';
			break;
	}
	$cat_title = 'Catégorie';

?>

<div id="BilbioModule" class="bilbioModule list">
	<header>
		<h1><?= $title ?></h1>
	</header>
	<form class="search" method="get" name="search" action="">
		<input type="hidden" name="page" value="1" />
		<div class="row">
			<div class="col-xs-12 col-sm-10">
				<div class="row">
					<div class="col-xs-12 col-sm-5">
						<label for="contentSearch" class="sr-only"><?= $searchLabel ?></label>
						<?= $this->formText('contentSearch',$this->params['contentSearch'],array('class'=>'form-control','placeholder'=>'Recherche','title'=>$searchLabel,'aria-label'=>$searchLabel))?>
					</div>
					<div class="col-xs-12 col-sm-2">dans</div>
					<div class="col-xs-12 col-sm-5">
						<label for="objectSearch" class="sr-only">Champ de la recherche</label>
						<?= $this->formSelect('objectSearch',$this->params['objectSearch'],array('class'=>'form-control','title'=>'Champ de la recherche','aria-label'=>'Champ de la recherche'), array( '' => 'Tous les champs' ) + Biblio_Model_Item_Table::$objectSearch )?>
					</div>
					<div class="col-xs-12">
					<span id="helpBlock" class="help-block">Les mots de moins de 3 caractères seront exclus de la recherche.</span>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-12 col-sm-6">
						<label for="category" class="sr-only">Catégorie recherchée</label>
						<?= $this->formSelect('category',$this->params['category'],array('class'=>'form-control','title'=>'Catégorie recherchée','aria-label'=>'Catégorie recherchée'), array( '' => 'Toutes les catégories' ) + $this->typeCategories )?>
					</div>
					<div class="col-xs-12 col-sm-6">
						<label for="order" class="sr-only">Trier par</label>
						<?= $this->formSelect('order',$this->order,array('class'=>'form-control','title'=>'Trier par','aria-label'=>'Trier par'), array( '' => 'Tri par défaut' ) + $this->orders )?>
					</div>
				</div>
			</div>
			<div class="col-xs-12 col-sm-2 btncol">
				<a class="btn btn-primary btn-md" href="<?= $this->url(array(),$url_route,true) ?>"><i class="fa fa-refresh"></i></a>
				<button class="btn btn-primary btn-md" title="Lancer la recherche" aria-label="Lancer la recherche"><i class="fa fa-search"></i></button>
			</div>
		</div>


		<div class="row">
			<div class="col-xs-12 searchAlpha">
			<span class="sr-only">Recherche Alphabétique (sur le nom de l'auteur) </span>

			<?php
				for($i=65; $i<=90 ; $i++)
				{
					echo '<a href="'. $this->url( array( 'namestartWith'=> chr($i) ),$url_route,true ) .'" '. ($this->params['namestartWith']==chr($i)?'class="active"':'') .' >'.chr($i).'</a> ';
				}
				echo '<a href="'. $this->url( array( 'namestartWith'=> '0-9' ),$url_route,true ) .'" '. ($this->params['namestartWith']=='0-9'?'class="active"':'') .'>#</a>';
			?>
			</div>
		</div>
		<?php if( !empty( $this->warning )) : ?>
		<p class="alert alert-warning"><?= $this->warning ?></p>
		<?php endif; ?>
	</form>

	<div class="row">
		<div class="col-xs-12 col-sm-6">
				<a href="<?= $this->url( array(),'biblio-cart',true ) ?>" class="btn btn-md btn-primary"><i class="fa fa-shopping-cart"></i> Voir ma commande</a>
		</div>
		<div class="col-xs-12 col-sm-6 pagecount">
		<?php if( $total > 0 ) : ?>
			Résultats de <?= $from ?> à <?= $to ?> sur <?= $total ?>
		<?php endif; ?>
		</div>
	</div>
	<hr>
<?php

	if( $total > 0 ) :
		foreach ($this->paginator as $item) :
			echo $this->partial('index/_item.phtml','biblio',array( 'item'=>$item,'length_icon'=>$length_icon,'length_title' => $length_title));
		endforeach;
		echo $this->paginator;
	else:
		echo '<p class="alert alert-warning">Pas de résultats</p>';
	endif;
?>
</div>
<?php
