From f78dc14cdb823cb50095c60dcc306eec87bb5d7b Mon Sep 17 00:00:00 2001
From: pbarroca <pbarroca@afi-sa.fr>
Date: Thu, 6 Mar 2014 17:55:16 +0100
Subject: [PATCH] rel #11947: Carthame ILS webservice settings accept a key

---
 cosmogramme/php/fonctions/objets_saisie.php | 119 +++++++++-----------
 1 file changed, 52 insertions(+), 67 deletions(-)

diff --git a/cosmogramme/php/fonctions/objets_saisie.php b/cosmogramme/php/fonctions/objets_saisie.php
index 90cb82e0e52..f407feadf16 100644
--- a/cosmogramme/php/fonctions/objets_saisie.php
+++ b/cosmogramme/php/fonctions/objets_saisie.php
@@ -1,4 +1,4 @@
-<?PHP
+<?php
 /**
  * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
  *
@@ -18,93 +18,80 @@
  * along with AFI-OPAC 2.0; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA 
  */
-//////////////////////////////////////////////////////////////////////////////
-//   OBJETS DE SAISIE
-//////////////////////////////////////////////////////////////////////////////
-function getComboSimple($name,$valeur,$liste)
-{
-	$combo='<select id="'.$name.'" name="'.$name.'">';
-	foreach($liste as $clef => $libelle)
-	{
-		if($valeur==$clef) $selected=" selected"; else $selected="";
-		$combo.='<option value="'.$clef.'"'.$selected.'>'.$libelle.'</option>';
+
+function getComboSimple($name, $valeur, $liste, $tous=false, $events='') {
+	if ('' != $events) 
+		$events = ' ' . $events;
+	$combo = '<select id="' . $name . '" name="' . $name . '" ' . $events . '>';
+	if ($tous)
+		$combo .= '<option value="">tous</option>';
+	foreach ($liste as $clef => $libelle) {
+		$selected = ($valeur == $clef) ? ' selected' : '';
+		$combo .= '<option value="' . $clef . '"' . $selected . '>' . $libelle . '</option>';
 	}
-	$combo.='</select>';
-	return $combo;
+	return $combo . '</select>';
 }
-function getComboCodif($name,$clef,$valeur,$events="",$tous=false)
-{
-	$data=fetchOne("Select liste from variables where clef='$clef'");
-	if($events > "") $events=" ".$events;
-	$champ_valeur='<select name="'.$name.'" id="'.$name.'" '.$events.'>';
-	if($tous == true) $champ_valeur.='<option value="">tous</option>';
-	$v=explode(chr(13).chr(10),$data);
-	for($i=0; $i<count($v); $i++)
-	{
-		$elem=explode(":",$v[$i]);
-		if(trim($elem[0])>"")
-		{
-			if($valeur==$elem[0]) $selected=" selected"; else $selected="";
-			$champ_valeur.='<option value="'.$elem[0].'"'.$selected.'>'.stripSlashes($elem[1]).'</option>';
-		}
+
+
+function getComboCodif($name, $clef, $valeur, $events='', $tous=false) {
+	$data = fetchOne('select liste from variables where clef=\''. $clef . '\'');
+	$v = array_filter(explode(chr(13) . chr(10), $data));
+	$values = [];
+	for ($i=0; $i < count($v); $i++) {
+		$elem = explode(':', $v[$i]);
+		if (!$elem[0])
+			continue;
+		$values[$elem[0]] = $elem[1];
 	}
-	$champ_valeur.='</select>';
-	return $champ_valeur;
+	return getComboSimple($name, $valeur, $values, $tous, $events);
 }
 
-function getComboTable($name,$table,$clef,$valeur,$condition="",$tous=false)
-{
+
+function getComboTable($name, $table, $clef, $valeur, $condition='', $tous=false) {
 	global $sql;
-	$req="Select $clef,libelle from $table";
-	$data=$sql->fetchAll($req." ".$condition);
-	$combo='<select name="'.$name.'">';
-	if($tous == true) $combo.='<option value="">tous</option>';
-	for($i=0; $i<count($data); $i++)
-	{
-		$elem=$data[$i];
-		if($valeur==$elem[$clef]) $selected=" selected"; else $selected="";
-		$combo.='<option value="'.$elem[$clef].'"'.$selected.'>'.$elem["libelle"].'</option>';
+	$req = 'select ' . $clef . ',libelle from ' .$table;
+	$data = $sql->fetchAll($req . ' ' . $condition);
+	$values = [];
+	for($i=0; $i < count($data); $i++) {
+		$elem = $data[$i];
+		$values[$elem[$clef]] = $elem['libelle'];
 	}
-	$combo.='</select>';
-	return $combo;
+	return getComboSimple($name, $valeur, $values, $tous);
 }
 
-function getChamp($id,$valeur,$taille)
-{
-	$champ='<input type="text" name="'.$id.'" value="'.$valeur .'"';
-	if($taille) $champ .=' size="'.$taille.'"';
-	$champ.='>';
-	return $champ;
+
+function getChamp($id, $valeur, $taille) {
+	return '<input type="text" name="'.$id.'" value="'.$valeur .'"'
+		. (($taille) ? ' size="' . $taille . '"': '') . '>';
 }
 
-function getTextarea($id,$valeur,$largeur,$hauteur)
-{
-	$champ='<textarea name="'.$id.'" cols="'.$largeur .'" rows="'.$hauteur.'">';
-	$champ.=$valeur.'</textarea>';
-	return $champ;
+
+function getTextarea($id, $valeur, $largeur, $hauteur) {
+	return '<textarea name="'.$id.'" cols="'.$largeur .'" rows="'.$hauteur.'">' 
+		. $valeur . '</textarea>';
 }
 
 
-// Blocs des parametres de communication avec le sigb
+/** 
+ * Blocs des parametres de communication avec le sigb 
+ */
 function getBlocsParams($id_bib, $type, $valeurs) {
 	$valeurs = unserialize($valeurs);
 	$types = getCodifsVariable("comm_sigb");
 
 	foreach($types as $item) {
 		$clef = $item['code'];
-		$display = ($clef == $type) ? 'block' : 'none';
-		$bloc .= '<div id="comm_' . $id_bib . '_' . $clef . '" style="display:' . $display . '">';
+		$bloc .= sprintf('<div id="comm_%s_%s" style="display:%s">',
+										 $id_bib, $clef, ($clef == $type) ? 'block' : 'none');
 		
-		// Parametres en fonction du type
-		unset($params);
-		unset($champs_params);
+		$params = [];
+		$champs_params = [];
 		$titres[0] = 'Paramètres';
 
-		if (in_array($clef, [COM_VSMART, COM_KOHA, COM_CARTHAME, 
-												 COM_NANOOK, COM_MICROBIB, COM_BIBLIXNET])) 
+		if (in_array($clef, [COM_VSMART, COM_NANOOK, COM_MICROBIB, COM_BIBLIXNET])) 
 			$champs_params[0] = ['url_serveur'];
 
-		if (COM_ORPHEE == $clef)
+		if (in_array($clef, [COM_ORPHEE, COM_CARTHAME]))
 			$champs_params[0] = ['url_serveur', 'key'];
 		
 		if ($clef == COM_KOHA)  
@@ -129,15 +116,13 @@ function getBlocsParams($id_bib, $type, $valeurs) {
 			$champs_params[1] = ['Autoriser_prolongations', 'Interdire_si_reservation', 
 													 'Nombre_max_par_document', 'Duree_en_jours', 'Anteriorite_max_en_jours'];
 		}
-		
 
-		// valorisation
 		$defaultInputRenderer = function($id, $valeur) {
 			return getChamp($id, $valeur,	30);
 		};
 
 		$cnt = count($champs_params);
-		for($i=0; $i < $cnt; $i++) {
+		for ($i=0; $i < $cnt; $i++) {
 			if (!$champs_params[$i])
 				continue;
 
@@ -145,7 +130,7 @@ function getBlocsParams($id_bib, $type, $valeurs) {
 			$bloc .= '<div style="margin-top:5px"><b>' . $titres[$i] . '</b></div>';
 			$bloc .= '<table>';
 
-			foreach($champs_params[$i] as $param)	{
+			foreach ($champs_params[$i] as $param)	{
 				$param_name = is_array($param) ? array_keys($param)[0] : $param;
 				$renderer = is_array($param) ? array_values($param)[0] : $defaultInputRenderer;
 				$valeur = $clef == $type ? $valeurs[$param_name] : '';
-- 
GitLab