From 30bcf39df9516de7fc0ff5a6c173dac68520694a Mon Sep 17 00:00:00 2001
From: Ghislain Loas <ghislo@sandbox.pergame.net>
Date: Mon, 3 Nov 2014 12:29:12 +0100
Subject: [PATCH] hotline_#16652_search_with_bib_filter fix to match correct
 post data type + valid front test

---
 .../opac/controllers/BibController.php        |  20 +-
 .../opac/views/scripts/bib/selection.phtml    |  20 +-
 library/Class/Bib.php                         | 259 +++++++++---------
 library/Class/Migration/Patchs.php            |   1 -
 .../View/Helper/TagRechercheSimple.php        |  54 ++--
 .../opac/controllers/BibControllerTest.php    |  33 ++-
 .../View/Helper/TagRechercheSimpleTest.php    |  31 ++-
 7 files changed, 218 insertions(+), 200 deletions(-)

diff --git a/application/modules/opac/controllers/BibController.php b/application/modules/opac/controllers/BibController.php
index 34ab52c8a29..d3ddf4ae2bf 100644
--- a/application/modules/opac/controllers/BibController.php
+++ b/application/modules/opac/controllers/BibController.php
@@ -89,28 +89,16 @@ class BibController extends ZendAfi_Controller_Action {
 
 	function selectionAction() {
 		$this->view->titre = $this->view->_('Sélection de bibliothèques pour la recherche');
-
 		$this->view->zones = Class_Zone::findAll();
-
-		$id_bibs = [];
+		$this->view->id_bibs_session = [];
 		if(array_isset('id_bibs', $_SESSION["selection_bib"]))
-			$id_bib = $_SESSION["selection_bib"]['id_bibs'];
-		if($id_bibs) {
-			$this->view->sel_bib = [];
-			$id_bibs=explode(",",$id_bibs);
-			foreach($id_bibs as $bib) $this->view->sel_bib[$bib]=true;
-		}
-		else
-			$this->view->sel_bib="all";
+			$this->view->id_bibs_session = $_SESSION["selection_bib"]['id_bibs'];
 
-		if($this->_request->isPost())
-			$this->_redirectToReferer();
 
 	}
 
-//------------------------------------------------------------------------------------------------------
-// Google maps
-//------------------------------------------------------------------------------------------------------
+
+
 	function mapviewAction() {
 		$id_bib = (int)$this->_request->getParam('id_bib');
 		if($id_bib<=0) $this->_redirect('opac/bib/index');
diff --git a/application/modules/opac/views/scripts/bib/selection.phtml b/application/modules/opac/views/scripts/bib/selection.phtml
index 75024f62af3..c30fefc1c8f 100644
--- a/application/modules/opac/views/scripts/bib/selection.phtml
+++ b/application/modules/opac/views/scripts/bib/selection.phtml
@@ -9,30 +9,22 @@ echo $this->tagAnchor('javascript:selectall()',
 echo $this->tagAnchor('javascript:deselectall()',
 											$this->_('Tout décocher'));
 ?>
-<form name="selection" method="post">
+<form name="selection" method="post" action="">
 <?php
 echo ('<ul>');
 foreach($this->zones as $zone )
 {
   echo '<li>' . $this->tag('h2', $zone->getLibelle());
-	$bibs = Class_Bib::findAllBy(['id_zone' => $zone->getId()]);
+	$bibs = Class_Bib::findAllBy(['id_zone' => $zone->getId(),
+																'visibilite' => 2]);
 	echo ('<ul>');
   foreach($bibs as $bib) {
- 		if($bib->getVisibilite() != "2")
-			continue;
-    $coche="";
-
-    if($this->sel_bib == "all")
-			$coche="checked";
-    elseif($this->sel_bib[$bib->getIdSite()] == true) {
-			$coche="checked";
-		}
+    $coche = in_array($bib->getId(), $this->id_bibs_session) ? ['checked' => 'checked'] : [];
 		echo $this->tag('li',
 										$this->tag('span', $bib->getLibelle()).
 										$this->tagInput(['type' => 'checkbox',
 																		 'name' => 'bib_select[]',
-																		 'checked' => $coche,
-																		 'value' => $bib->getIdSite()]));
+																		 'value' => $bib->getIdSite()] + $coche));
   }
 	echo('</ul></li>');
 }
@@ -40,8 +32,6 @@ echo ('</ul>');
 echo $this->tagInput(['type' => 'submit',
 											'value' => $this->_('Valider la sélection'),
 											'name' => 'Valider']);
-
 echo ('</form>');
-
 $this->closeBoite();
 ?>
diff --git a/library/Class/Bib.php b/library/Class/Bib.php
index 2c302f17631..d29bd6c3409 100644
--- a/library/Class/Bib.php
+++ b/library/Class/Bib.php
@@ -23,13 +23,11 @@
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 require_once dirname(__FILE__)."/CompositeBuilder.php";
 
-class BibCSite extends Zend_Db_Table_Abstract
-{
+
+
+class BibCSite extends Zend_Db_Table_Abstract {
 	protected $_name = 'bib_c_site';
 }
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-//																							 Class_Bib -> gestion des bibliothèques
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
 
 
@@ -105,27 +103,30 @@ class BibLoader extends Storm_Model_Loader {
 		if(!is_array($ids))
 			$ids = explode(',',$ids);
 
-		$zones = [];
-		foreach($ids as $id) {
-			$zones[] = Class_Bib::find($id)->getId();
-		}
+		$zones = Class_Zone::findAll();
 
 		$bibs_by_zones = [];
-		foreach($zones as $zone_id) {
-			$bibs_by_zones[$zone_id] =
-				array_filter(Class_Bib::findAllByIdZone($zone_id), function($bib) {return $bib->getVisibilite() == 2 ;});
+		foreach($zones as $zone) {
+			$bibs_by_zones[$zone->getId()] = Class_Bib::findAllBy(['id_zone' => $zone->getId(),
+																														 'visibilite' => 2]);
 		}
 
 		$selected_zones = [];
+		$select_bibs_not_in_zone = [];
 		foreach($bibs_by_zones as $id => $bibs) {
+			if(!$ids)
+				continue;
 			$bibs_ids = [];
 			foreach($bibs as $bib)
 				$bibs_ids[] = $bib->getId();
 
-			if(0 == count(array_diff($bibs_ids, $ids)))
+			if(0 == count(array_diff($bibs_ids, $ids))) {
 				$selected_zones[] = $id;
+				$ids = array_diff($ids, $bibs_ids);
+			}
+
 		}
-		return $selected_zones;
+		return [$selected_zones, $ids];
 	}
 }
 
@@ -188,8 +189,8 @@ class Class_Bib extends Storm_Model_Abstract {
 																						'role' => 'bib',
 																						'dependents' => 'delete'],
 													'localisations' => ['model' => 'Class_Localisation',
-																							 'role' => 'bib',
-																							 'order' => 'libelle'],
+																							'role' => 'bib',
+																							'order' => 'libelle'],
 													'plans' => ['model' => 'Class_Plan',
 																			'role' => 'bib',
 																			'order' => 'libelle']];
@@ -280,10 +281,10 @@ class Class_Bib extends Storm_Model_Abstract {
 	{
 		$where = '';
 		if($id_zone and $id_zone !="ALL")
-		{
-			if($id_zone=="PORTAIL") $id_zone=0;
-			$where=" Where ID_ZONE=".$id_zone;
-		}
+			{
+				if($id_zone=="PORTAIL") $id_zone=0;
+				$where=" Where ID_ZONE=".$id_zone;
+			}
 		$bibs=fetchAll("select * from bib_c_site".$where." order by LIBELLE");
 		if ($bibs==false) $bibs = array();
 		return $bibs;
@@ -336,19 +337,19 @@ class Class_Bib extends Storm_Model_Abstract {
 	{
 		$ville=addslashes($ville);
 		if($visibilite > "1")
-		{
-			$controle=fetchOne("select count(*) from int_bib where id_bib=$id_bib");
-			if(!$controle) sqlExecute("insert into int_bib(id_bib,nom_court) Values($id_bib,'$ville')");
-			else sqlExecute("update int_bib set nom_court='$ville' where id_bib=$id_bib");
-		}
+			{
+				$controle=fetchOne("select count(*) from int_bib where id_bib=$id_bib");
+				if(!$controle) sqlExecute("insert into int_bib(id_bib,nom_court) Values($id_bib,'$ville')");
+				else sqlExecute("update int_bib set nom_court='$ville' where id_bib=$id_bib");
+			}
 		else
-		{
-			$controle=fetchOne("select count(*) from exemplaires where id_bib=$id_bib");
-			if($controle) return false;
-			sqlExecute("delete from int_bib where id_bib=$id_bib");
-			sqlExecute("delete from notices_succintes where id_bib=$id_bib");
-			sqlExecute("delete from integrations where id_bib=$id_bib");
-		}
+			{
+				$controle=fetchOne("select count(*) from exemplaires where id_bib=$id_bib");
+				if($controle) return false;
+				sqlExecute("delete from int_bib where id_bib=$id_bib");
+				sqlExecute("delete from notices_succintes where id_bib=$id_bib");
+				sqlExecute("delete from integrations where id_bib=$id_bib");
+			}
 	}
 
 	// ----------------------------------------------------------------
@@ -362,18 +363,18 @@ class Class_Bib extends Storm_Model_Abstract {
 		$zone_class = new Class_Zone();
 		$zone_array = $zone_class->getZones($id_zone);
 		foreach ($zone_array as $zone)
-		{
-			$html[]='<optgroup label="'.$zone["LIBELLE"].'" style="font-style:normal;color:#FF6600">';
-			$bib_array = $this->getBibs($zone["ID_ZONE"]);
-			// les bibs
-			if(!$bib_array) continue;
-			foreach ($bib_array as $bib)
 			{
-				if ($id_bib == $bib["ID_SITE"]) $selected='selected="selected"'; else $selected='';
-				$html[]='<option style="color:#575757" value="'.$bib["ID_SITE"].'" '.$selected.'>'.$bib["LIBELLE"].'</option>';
+				$html[]='<optgroup label="'.$zone["LIBELLE"].'" style="font-style:normal;color:#FF6600">';
+				$bib_array = $this->getBibs($zone["ID_ZONE"]);
+				// les bibs
+				if(!$bib_array) continue;
+				foreach ($bib_array as $bib)
+					{
+						if ($id_bib == $bib["ID_SITE"]) $selected='selected="selected"'; else $selected='';
+						$html[]='<option style="color:#575757" value="'.$bib["ID_SITE"].'" '.$selected.'>'.$bib["LIBELLE"].'</option>';
+					}
+				$html[]='</optgroup>';
 			}
-			$html[]='</optgroup>';
-		}
 		$html[]='</select>';
 		return implode('',$html);
 	}
@@ -384,47 +385,47 @@ class Class_Bib extends Storm_Model_Abstract {
 	public function getAllBibByIdZone($id_zone=0)
 	{
 		try
-		{
-			$BibCSite = new BibCSite();
-			if($id_zone == 0)
 			{
-				$select = $BibCSite->getAdapter()->select()
-					->from('bib_c_site',array('ID_SITE'=>'ID_SITE','LIBELLE'=>'LIBELLE', 'ID_ZONE'=>'ID_ZONE','VILLE'=>'VILLE','MAIL'=>'MAIL','URL_WEB'=>'URL_WEB','TELEPHONE'=>'TELEPHONE','VISIBILITE'=>'VISIBILITE'))
-					->where('ID_ZONE >=?', 0)
-					->order('VILLE');
-				$stmt = $select->query();
-				$row = $stmt->fetchAll();
-				return $row;
-			}
-			else
-			{
-				$select = $BibCSite->getAdapter()->select()
-					->from('bib_c_site',array('ID_SITE'=>'ID_SITE','LIBELLE'=>'LIBELLE', 'ID_ZONE'=>'ID_ZONE','VILLE'=>'VILLE','MAIL'=>'MAIL','URL_WEB'=>'URL_WEB','TELEPHONE'=>'TELEPHONE','VISIBILITE'=>'VISIBILITE'))
-					->where('ID_ZONE=?', $id_zone)
-					->order('VILLE');
-				$stmt = $select->query();
-				$row = $stmt->fetchAll();
-				return $row;
-			}
-		}catch (Exception $e)
-		{
-			logErrorMessage('Class: Class_Zone; Function: getAllBibByIdZone' . NL . $e->getMessage());
-			return $this->_dataBaseError;
-		}
+				$BibCSite = new BibCSite();
+				if($id_zone == 0)
+					{
+						$select = $BibCSite->getAdapter()->select()
+															 ->from('bib_c_site',array('ID_SITE'=>'ID_SITE','LIBELLE'=>'LIBELLE', 'ID_ZONE'=>'ID_ZONE','VILLE'=>'VILLE','MAIL'=>'MAIL','URL_WEB'=>'URL_WEB','TELEPHONE'=>'TELEPHONE','VISIBILITE'=>'VISIBILITE'))
+															 ->where('ID_ZONE >=?', 0)
+															 ->order('VILLE');
+						$stmt = $select->query();
+						$row = $stmt->fetchAll();
+						return $row;
+					}
+				else
+					{
+						$select = $BibCSite->getAdapter()->select()
+															 ->from('bib_c_site',array('ID_SITE'=>'ID_SITE','LIBELLE'=>'LIBELLE', 'ID_ZONE'=>'ID_ZONE','VILLE'=>'VILLE','MAIL'=>'MAIL','URL_WEB'=>'URL_WEB','TELEPHONE'=>'TELEPHONE','VISIBILITE'=>'VISIBILITE'))
+															 ->where('ID_ZONE=?', $id_zone)
+															 ->order('VILLE');
+						$stmt = $select->query();
+						$row = $stmt->fetchAll();
+						return $row;
+					}
+			}catch (Exception $e)
+				{
+					logErrorMessage('Class: Class_Zone; Function: getAllBibByIdZone' . NL . $e->getMessage());
+					return $this->_dataBaseError;
+				}
 	}
 
 	public function getBibById($id_bib)
 	{
 		try
-		{
-			$BibCSite = new BibCSite();
-			$where = $BibCSite->getAdapter()->quoteInto('ID_SITE=?', $id_bib);
-			return $fetch = $BibCSite->fetchRow($where);
-		}catch (Exception $e)
-		{
-			logErrorMessage('Class: Class_Zone; Function: getBibById' . NL . $e->getMessage());
-			return $this->_dataBaseError;
-		}
+			{
+				$BibCSite = new BibCSite();
+				$where = $BibCSite->getAdapter()->quoteInto('ID_SITE=?', $id_bib);
+				return $fetch = $BibCSite->fetchRow($where);
+			}catch (Exception $e)
+				{
+					logErrorMessage('Class: Class_Zone; Function: getBibById' . NL . $e->getMessage());
+					return $this->_dataBaseError;
+				}
 	}
 
 	// Rend l'image si trouve, sinon rend l'url
@@ -440,12 +441,12 @@ class Class_Bib extends Storm_Model_Abstract {
 		$html[]='<select name="statut" id="statut" style="width:100%">';
 		$i = 0;
 		foreach ($this->statut_bib as $statut)
-		{
-			if ($id_selected == $i) $selected='selected="selected"';
-			else $selected='';
-			$html[]='<option value="'.$i.'" '.$selected.'>'.$statut.'</option>';
-			$i++;
-		}
+			{
+				if ($id_selected == $i) $selected='selected="selected"';
+				else $selected='';
+				$html[]='<option value="'.$i.'" '.$selected.'>'.$statut.'</option>';
+				$i++;
+			}
 		$html[]='</select>';
 		return implode('',$html);
 	}
@@ -479,25 +480,25 @@ class Class_Bib extends Storm_Model_Abstract {
 	private function treeConfig($type) {
 		// liste des tables, classes, ... pour chaque type de données
 		$configs = array(
-								 'rss' => array(
-																'cat_class' => 'Class_RssModelCategorie',
-																'item_class' => 'Class_RssModelFlux',
-																'cat_table' => 'rss_categorie',
-																'item_table' => 'rss_flux',
-																'cat_id_field' => 'ID_CAT',
-																'item_id_field' => 'ID_RSS',
-																'cat_parent_id_field' => 'ID_CAT_MERE',
-																'require' => 'Rss.php'),
-								 'sito' => array(
-																'cat_class' => 'Class_SitothequeModelCategorie',
-																'item_class' => 'Class_SitothequeModelSite',
-																'cat_table' => 'sito_categorie',
-																'item_table' => 'sito_url',
-																'cat_id_field' => 'ID_CAT',
-																'item_id_field' => 'ID_SITO',
-																'cat_parent_id_field' => 'ID_CAT_MERE',
-																'require' => 'Sitotheque.php')
-										 );
+										 'rss' => array(
+																		'cat_class' => 'Class_RssModelCategorie',
+																		'item_class' => 'Class_RssModelFlux',
+																		'cat_table' => 'rss_categorie',
+																		'item_table' => 'rss_flux',
+																		'cat_id_field' => 'ID_CAT',
+																		'item_id_field' => 'ID_RSS',
+																		'cat_parent_id_field' => 'ID_CAT_MERE',
+																		'require' => 'Rss.php'),
+										 'sito' => array(
+																		 'cat_class' => 'Class_SitothequeModelCategorie',
+																		 'item_class' => 'Class_SitothequeModelSite',
+																		 'cat_table' => 'sito_categorie',
+																		 'item_table' => 'sito_url',
+																		 'cat_id_field' => 'ID_CAT',
+																		 'item_id_field' => 'ID_SITO',
+																		 'cat_parent_id_field' => 'ID_CAT_MERE',
+																		 'require' => 'Sitotheque.php')
+		);
 		return $configs[$type];
 	}
 
@@ -515,10 +516,10 @@ class Class_Bib extends Storm_Model_Abstract {
 	/*
 		Retourne la liste des arborescences bibliothèques / catégories / articles qui ont des articles visibles
 		Utilisé pour construire le JSON envoyer au widget jquery TreeSelect.
-	 * type = sito | rss
-	 * id_bib : l'id de la bib, 0 signifie toutes les bibliothèques
-	 * do_load_items: si true, les items (articles, flux ou sites) ne seront chargés (sinon seulement les catégories).
-	*/
+		* type = sito | rss
+		* id_bib : l'id de la bib, 0 signifie toutes les bibliothèques
+		* do_load_items: si true, les items (articles, flux ou sites) ne seront chargés (sinon seulement les catégories).
+		*/
 	public function buildBibTree($id_bib, $type, $do_load_items){
 		//LL: TODO quand j'aurai le courage, faire une class de base pour les RSS/Sito/CMS et mettre en
 		// place du Strategy pour supprimer toutes les duplications de code
@@ -589,20 +590,20 @@ class Class_Bib extends Storm_Model_Abstract {
 	{
 		$errorMessage = $this->verifData($data);
 		if ($errorMessage == '')
-		{
-			try
 			{
-				$BibCSite = new BibCSite();
-				$BibCSite->insert($data);
-				// Recup id pour maj cosmogramme
-				$id_bib=fetchOne("select max(ID_SITE) from bib_c_site");
-				$this->majCosmogramme($id_bib,$data["VILLE"],$data["VISIBILITE"]);
-			}catch (Exception $e)
-			{
-				logErrorMessage('Class: Class_Bib; Function: addBib' . NL . $e->getMessage());
-				$errorMessage = $this->_dataBaseError;
+				try
+					{
+						$BibCSite = new BibCSite();
+						$BibCSite->insert($data);
+						// Recup id pour maj cosmogramme
+						$id_bib=fetchOne("select max(ID_SITE) from bib_c_site");
+						$this->majCosmogramme($id_bib,$data["VILLE"],$data["VISIBILITE"]);
+					}catch (Exception $e)
+						{
+							logErrorMessage('Class: Class_Bib; Function: addBib' . NL . $e->getMessage());
+							$errorMessage = $this->_dataBaseError;
+						}
 			}
-		}
 		return $errorMessage;
 	}
 
@@ -611,19 +612,19 @@ class Class_Bib extends Storm_Model_Abstract {
 	{
 		$errorMessage = $this->verifData($data);
 		if ($errorMessage == '')
-		{
-			try
 			{
-				$BibCSite = new BibCSite();
-				$where = $BibCSite->getAdapter()->quoteInto('ID_SITE=?', $id_bib);
-				$BibCSite->update($data, $where);
-				$this->majCosmogramme($id_bib,$data["VILLE"],$data["VISIBILITE"]);
-			}catch (Exception $e)
-			{
-				logErrorMessage('Class: Class_Zone; Function: editBib' . NL . $e->getMessage());
-				$errorMessage = $this->_dataBaseError;
+				try
+					{
+						$BibCSite = new BibCSite();
+						$where = $BibCSite->getAdapter()->quoteInto('ID_SITE=?', $id_bib);
+						$BibCSite->update($data, $where);
+						$this->majCosmogramme($id_bib,$data["VILLE"],$data["VISIBILITE"]);
+					}catch (Exception $e)
+						{
+							logErrorMessage('Class: Class_Zone; Function: editBib' . NL . $e->getMessage());
+							$errorMessage = $this->_dataBaseError;
+						}
 			}
-		}
 		return $errorMessage;
 	}
 
diff --git a/library/Class/Migration/Patchs.php b/library/Class/Migration/Patchs.php
index f6ba590154e..3baeea721ac 100644
--- a/library/Class/Migration/Patchs.php
+++ b/library/Class/Migration/Patchs.php
@@ -136,7 +136,6 @@ class Class_Migration_Patchs {
 
 			try {
 				$sql = Zend_Registry::get('sql');
-				xdebug_break();
 				$sql->execute(trim($instruction));
 
 			} catch(Exception $e)	{
diff --git a/library/ZendAfi/View/Helper/TagRechercheSimple.php b/library/ZendAfi/View/Helper/TagRechercheSimple.php
index 7889e558c7a..e2d092b3bbb 100644
--- a/library/ZendAfi/View/Helper/TagRechercheSimple.php
+++ b/library/ZendAfi/View/Helper/TagRechercheSimple.php
@@ -56,8 +56,6 @@ class ZendAfi_View_Helper_TagRechercheSimple extends Zend_View_Helper_HtmlElemen
 
 
 	public function renderSelectionBib() {
-		xdebug_break();
-
 		if ((int)$this->preferences["select_bib"] !== 1)
 			return '';
 
@@ -65,7 +63,7 @@ class ZendAfi_View_Helper_TagRechercheSimple extends Zend_View_Helper_HtmlElemen
 
 		$input = $this->view->tagInput(['type' => 'hidden',
 																		'name' => 'bib_select',
-																		'value' => $bib_ids]);
+																		'value' => implode(',',$bib_ids)]);
 
 		$anchor = $this->view->tagAnchor(['module' => 'opac',
 																			'controller' => 'bib',
@@ -74,7 +72,7 @@ class ZendAfi_View_Helper_TagRechercheSimple extends Zend_View_Helper_HtmlElemen
 
 		$message = $this->view->tag('p', $this->renderSelectBibMessage($bib_ids));
 
-		return $this->view->tag('div', $input . $message . $anchor);
+		return $this->view->tag('div', $input . $message . $anchor, ['class' => 'selected_bibs_info']);
 	}
 
 
@@ -85,33 +83,39 @@ class ZendAfi_View_Helper_TagRechercheSimple extends Zend_View_Helper_HtmlElemen
 		if(Class_Bib::areAllBibsSelected($bib_ids))
 			return $this->view->_('La recherche s\'effectue dans tout le réseau.');
 
-
 		$message = '';
 
-		if($zones = Class_Bib::getSelectedZones($bib_ids)) {
+		$grouped_ids = Class_Bib::getSelectedZones($bib_ids);
+		$zones_ids = $grouped_ids[0];
+		$bib_ids = $grouped_ids[1];
+
+		if($zones_ids) {
 			$zones_libelles = [];
-			foreach($zones as $zone) {
-				$zones_libelles[] = Class_Zone::find($zone)->getLibelle();
+			foreach($zones_ids as $zone_id) {
+				if(!$zone = Class_Zone::find($zone_id))
+					continue;
+				$zones_libelles[] = $zone->getLibelle();
 			}
 
-			$message =  $this->view->_plural(count($zones),
-																	'Aucune zone de sélectionnée.',
-																	'La recherche s\'effectue dans toute la zone %s.',
-																	'La recherche s\'effectue dans toutes les zones %s.',
-																	implode(', ', $zones_libelles));
+			$message =  $this->view->tag('span', $this->view->_plural(count($zones_libelles),
+																																'Aucune zone de sélectionnée.',
+																																'La recherche s\'effectue dans la zone: %s.',
+																																'La recherche s\'effectue dans les zones: %s.',
+																																$this->view->tag('b', implode(', ', $zones_libelles))));
 		}
 
-		xdebug_break();
-		$bib_ids_array = explode(',', $bib_ids);
+		if(!$bib_ids)
+			return $message;
+
 		$bibs_labels = [];
-		foreach($bib_ids_array as $id)
+		foreach($bib_ids as $id)
 			$bibs_labels[] = Class_Bib::find($id)->getLibelle();
 
-		return $message .= $this->view->_plural(count($bibs_labels),
-																						'Aucune bib de sélectionnée.',
-																						'La recherche s\'effectue dans la bibliothèque de %s.',
-																						'La recherche s\'effectue dans les bibliothèques de %s.',
-																						implode(', ', $bibs_labels));
+		return $message .= $this->view->tag('span', $this->view->_plural(count($bibs_labels),
+																																		 'Aucune bib de sélectionnée.',
+																																		 'La recherche s\'effectue dans la bibliothèque: %s.',
+																																		 'La recherche s\'effectue dans les bibliothèques: %s.',
+																																		 $this->view->tag('b',implode(', ', $bibs_labels))));
 	}
 
 
@@ -130,8 +134,8 @@ class ZendAfi_View_Helper_TagRechercheSimple extends Zend_View_Helper_HtmlElemen
 
 		if($this->preferences["select_doc"] and $this->division!="2")
 			$contenu.= sprintf('<div style="margin-top:5px"><label for="select_type_doc">%s</label>%s</div>',
-															 $this->view->_('Type de document'),
-															 $this->getComboTypesDocs());
+												 $this->view->_('Type de document'),
+												 $this->getComboTypesDocs());
 
 		if($this->preferences["select_annexe"] and $this->division!="2")	{
 			$contenu.=$this->getComboAnnexes();
@@ -178,8 +182,8 @@ class ZendAfi_View_Helper_TagRechercheSimple extends Zend_View_Helper_HtmlElemen
 								'style' => 'width:'.$this->preferences["largeur"].'px',
 								'onkeypress' => 'if (event.keyCode == 13) {this.form.submit();return false;}'];
 
-			$ret= '<input '.$this->_htmlAttribs($attribs).' />'.
-						'<input name="button" type="submit" class="submit" value="" />';
+		$ret= '<input '.$this->_htmlAttribs($attribs).' />'.
+			'<input name="button" type="submit" class="submit" value="" />';
 
 		if ($this->preferences["exemple"])
 			$ret.='<div>'.$this->preferences["exemple"].'</div>';
diff --git a/tests/application/modules/opac/controllers/BibControllerTest.php b/tests/application/modules/opac/controllers/BibControllerTest.php
index e0ce54bc2d5..2ba25d9eba8 100644
--- a/tests/application/modules/opac/controllers/BibControllerTest.php
+++ b/tests/application/modules/opac/controllers/BibControllerTest.php
@@ -365,7 +365,7 @@ abstract class BibControllerBibSelectionAbstractTestCase extends AbstractControl
 
 
 
-class BibControllerBibSelectionTest extends BibControllerBibSelectionAbstractTestCase {
+class BibControllerBibSelectionWithEmptySessionTest extends BibControllerBibSelectionAbstractTestCase {
 	public function setUp() {
 		parent::setUp();
 		$this->dispatch('bib/selection', true);
@@ -398,6 +398,35 @@ class BibControllerBibSelectionTest extends BibControllerBibSelectionAbstractTes
 
 
 
+class BibControllerBibSelectionWithBibsIdsInSessionTest extends BibControllerBibSelectionAbstractTestCase {
+	public function setUp() {
+		parent::setUp();
+		$_SESSION['selection_bib'] = ['id_bibs' => [1, 2]];
+		$this->dispatch('bib/selection', true);
+	}
+
+
+	/** @test */
+	public function cairoShouldBeChecked() {
+		$this->assertXPath('//li/input[@checked="checked"][@value="1"]');
+	}
+
+
+	/** @test */
+	public function casablancaShouldBeChecked() {
+		$this->assertXPath('//li/input[@checked="checked"][@value="2"]');
+	}
+
+
+	/** @test */
+	public function parisShouldNotBeChecked() {
+		$this->assertNotXPath('//li/input[@checked="checked"][@value="3"]');
+	}
+}
+
+
+
+
 class BibControllerBibSelectionPostDispatchTest extends BibControllerBibSelectionAbstractTestCase {
 	public function setUp() {
 		parent::setUp();
@@ -406,7 +435,7 @@ class BibControllerBibSelectionPostDispatchTest extends BibControllerBibSelectio
 
 
 	/** @test */
-	public function shoudRedirectToExpeectedReferer() {
+	public function shoudRedirectToExpectedReferer() {
 		$this->assertRedirectTo('http://my-bokeh.fr');
 	}
 
diff --git a/tests/library/ZendAfi/View/Helper/TagRechercheSimpleTest.php b/tests/library/ZendAfi/View/Helper/TagRechercheSimpleTest.php
index 598fa72410d..dd0447e093d 100644
--- a/tests/library/ZendAfi/View/Helper/TagRechercheSimpleTest.php
+++ b/tests/library/ZendAfi/View/Helper/TagRechercheSimpleTest.php
@@ -102,7 +102,7 @@ class ZendAfi_View_Helper_TagRechercheSimpleTestWithSessionParams extends ViewHe
 									 ['id' => 3,
 									  'libelle' => 'US']);
 
-		$cairo = $this->fixture('Class_Bib',
+		$chicago = $this->fixture('Class_Bib',
 														['id' => 4,
 														 'id_site' => 1,
 														 'libelle' => 'Chicago',
@@ -123,20 +123,27 @@ class ZendAfi_View_Helper_TagRechercheSimpleTestWithSessionParams extends ViewHe
 																	'visibilite' => 2,
 																	'id_zone' => 1]);
 
-		$casablanca = $this->fixture('Class_Bib',
+		$paris = $this->fixture('Class_Bib',
 																 ['id' => 3,
 																	'id_site' => '2',
 																	'libelle' => 'Paris',
 																	'visibilite' => 2,
 																	'id_zone' => 2]);
 
+		$berlin = $this->fixture('Class_Bib',
+														 ['id' => 78,
+															'id_site' => 78,
+															'libelle' => 'Berlin',
+															'id_zone' => 2,
+															'visibilite' => 2]);
+
 		$this->_preferences['select_bib'] = '1';
 	}
 
 
   /** @test */
 	public function withSelectionBibShouldPostExpectedValue() {
-		$_SESSION['selection_bib']  = ['id_bibs' => '1,2,3'];
+		$_SESSION['selection_bib']  = ['id_bibs' => [1,2,3]];
 		$html = $this->_helper->tagRechercheSimple($this->_preferences, 1);
 		$this->assertXPath($html, '//form//input[@name="bib_select"][@type="hidden"][@value="1,2,3"]');
 	}
@@ -152,23 +159,23 @@ class ZendAfi_View_Helper_TagRechercheSimpleTestWithSessionParams extends ViewHe
 
 	/** @test */
 	public function withSelectedBib3MessageShouldBeAsExpected() {
-		$_SESSION['selection_bib']  = ['id_bibs' => '3'];
+		$_SESSION['selection_bib']  = ['id_bibs' => [3]];
 		$html = $this->_helper->tagRechercheSimple($this->_preferences, 1);
-		$this->assertXPathContentContains($html, '//div//p', utf8_encode('La recherche s\'effectue dans la bibliothèque de Paris.'));
+		$this->assertXPathContentContains($html, '//div//p/span/b', 'Paris');
 	}
 
 
 	/** @test */
 	public function withSelectedBib1And3MessageShouldBeAsExpected() {
-		$_SESSION['selection_bib']  = ['id_bibs' => '1,3'];
+		$_SESSION['selection_bib']  = ['id_bibs' => [1,3]];
 		$html = $this->_helper->tagRechercheSimple($this->_preferences, 1);
-		$this->assertXPathContentContains($html, '//div//p', utf8_encode('La recherche s\'effectue dans les bibliothèques de Cairo, Paris.'));
+		$this->assertXPathContentContains($html, '//div//p/span/b', 'Cairo, Paris');
 	}
 
 
 	/** @test */
 	public function withSelectionBibAllMessageShouldBeAsExpected() {
-		$_SESSION['selection_bib']  = ['id_bibs' => '1,2,3,4'];
+		$_SESSION['selection_bib']  = ['id_bibs' => [1, 2, 3, 4, 78]];
 		$html = $this->_helper->tagRechercheSimple($this->_preferences, 1);
 		$this->assertXPathContentContains($html, '//div//p', utf8_encode('La recherche s\'effectue dans tout le réseau.'));
 	}
@@ -176,17 +183,17 @@ class ZendAfi_View_Helper_TagRechercheSimpleTestWithSessionParams extends ViewHe
 
 	/** @test */
 	public function withSelectionBib1And2MessageShouldBeAsExpected() {
-		$_SESSION['selection_bib']  = ['id_bibs' => '1,2'];
+		$_SESSION['selection_bib']  = ['id_bibs' => [1,2]];
 		$html = $this->_helper->tagRechercheSimple($this->_preferences, 1);
-		$this->assertXPathContentContains($html, '//div//p', utf8_encode('La recherche s\'effectue dans toute la zone Africa.'));
+		$this->assertXPathContentContains($html, '//div//p/span/b', 'Africa');
 	}
 
 
 		/** @test */
 	public function withSelectionBibByZone1and2MessageShouldBeAsExpected() {
-		$_SESSION['selection_bib']  = ['id_bibs' => '1,2,3'];
+		$_SESSION['selection_bib']  = ['id_bibs' => [1,2,3,78]];
 		$html = $this->_helper->tagRechercheSimple($this->_preferences, 1);
-		$this->assertXPathContentContains($html, '//div//p', utf8_encode('La recherche s\'effectue dans toutes les zones Africa, Europe.'));
+		$this->assertXPathContentContains($html, '//div//p/span/b', 'Africa, Europe');
 	}
 }
 ?>
\ No newline at end of file
-- 
GitLab