diff --git a/cosmogramme/php/classes/classe_abonne.php b/cosmogramme/php/classes/classe_abonne.php index 30df14938f47b47a5a338c1f6f5b6ff99b8e317a..b9eadd615cecc9573a193b3a5a6777e6dd51c57b 100644 --- a/cosmogramme/php/classes/classe_abonne.php +++ b/cosmogramme/php/classes/classe_abonne.php @@ -39,10 +39,22 @@ class abonne $profil=fetchEnreg("select * from profil_donnees where id_profil=$id_profil"); $this->type_accents=$profil["accents"]; $attribs=unserialize($profil["attributs"]); - if($profil["format"]==4) $this->champs=$attribs[5]["xml_champs_abonne"]; - else $this->champs=explode(";",$attribs[1]["champs"]); + if($profil["format"]==4) + $this->champs=$attribs[5]["xml_champs_abonne"]; + else + $this->champs=explode(";",$attribs[1]["champs"]); } + + public function setChamps($champs) { + $this->champs = $champs; + } + + public function setidBib($id_bib) { + $this->id_bib = $id_bib; + } + + // ---------------------------------------------------------------- // Import d'une fiche // ---------------------------------------------------------------- @@ -57,78 +69,98 @@ class abonne // ---------------------------------------------------------------- public function importFicheAscii($data) { + xdebug_break(); // Transco accents $data=$this->changeAccents($data); // Données d'import $data=explode(chr(9),$data); for($i=0; $i<count($this->champs); $i++) - { - $colonne=$this->champs[$i]; - if($colonne!="NULL") $enreg[$colonne]=$data[$i]; - } + { + $colonne=$this->champs[$i]; + if($colonne!="NULL") + $enreg[$colonne]=$data[$i]; + } // Completer l'enregistrement - $enreg["ID_SITE"]=$this->id_bib; - $enreg["LOGIN"]=$enreg["IDABON"]; - $enreg["ROLE"]="abonne_sigb"; - $enreg["ROLE_LEVEL"]=2; - $enreg["STATUT"]=0; - if ($enreg["NUM_CARTE"] && strlen($enreg["NUM_CARTE"]>0)) { + $enreg = $this->prepareData($enreg); + + if (isset($enreg["NUM_CARTE"]) && strlen($enreg["NUM_CARTE"]>0)) { $enreg["IDABON"]=$enreg["NUM_CARTE"]; unset($enreg["NUM_CARTE"]); } - if((int)$enreg["ORDREABON"] <1 ) $enreg["ORDREABON"]=1; - if(strlen($enreg["NAISSANCE"]) == 10) $enreg["NAISSANCE"]=rendDate($enreg["NAISSANCE"], 0); - $enreg["DATE_DEBUT"]=rendDate($enreg["DATE_DEBUT"], 0); - $enreg["DATE_FIN"]=rendDate($enreg["DATE_FIN"], 0); - if(!$enreg["PASSWORD"] and $enreg["NAISSANCE"]) $enreg["PASSWORD"]=rendDate($enreg["NAISSANCE"],1); + if((int)$enreg["ORDREABON"] <1 ) + $enreg["ORDREABON"]=1; + + if(isset($enreg["NAISSANCE"]) && (strlen($enreg["NAISSANCE"]) == 10)) + $enreg["NAISSANCE"]=rendDate($enreg["NAISSANCE"], 0); + + if(!$enreg["PASSWORD"] and $enreg["NAISSANCE"]) + $enreg["PASSWORD"]=rendDate($enreg["NAISSANCE"],1); - // Ecrire - global $sql; - $id_user=$sql->fetchOne("select ID_USER from bib_admin_users where LOGIN='".$enreg["LOGIN"]."' and ID_SITE=".$this->id_bib." and PASSWORD='".str_replace("'", "\'", $enreg["PASSWORD"])."'"); - if(!$id_user) $sql->insert("bib_admin_users",$enreg); - else $sql->update("update bib_admin_users set @SET@ where ID_USER=$id_user",$enreg); + $this->saveorUpdateInDB($enreg); } // ---------------------------------------------------------------- // Import d'une fiche en XML // ---------------------------------------------------------------- - public function importFicheXml($data) - { + public function importFicheXml($data){ // Transco accents $data=$this->changeAccents($data); - + // Données d'import $data=new SimpleXMLElement($data); $nombre=count($this->champs); - foreach($this->champs as $champ => $balise) - { - if($balise) - { + foreach($this->champs as $champ => $balise) { + if($balise){ $cmd="\$enreg['$champ']=(string)\$data->".addslashes($balise).";"; eval($cmd); } } + $enreg = $this->prepateData($enreg); + // formattage des dates $enreg["NAISSANCE"]=rendDate($enreg["NAISSANCE"], 0); - $enreg["DATE_DEBUT"]=rendDate($enreg["DATE_DEBUT"], 0); - $enreg["DATE_FIN"]=rendDate($enreg["DATE_FIN"], 0); // valeurs par défaut + if(!$enreg["ORDREABON"]) + $enreg["ORDREABON"]=1; + + // Ecrire + + + $this->saveOrUpdateInDB($id_user,$enreg); + } + + + protected function prepareData($enreg) { + $enreg["DATE_DEBUT"]= isset($enreg["DATE_DEBUT"]) ? rendDate($enreg["DATE_DEBUT"], 0) : ''; + $enreg["DATE_FIN"]= isset($enreg["DATE_FIN"]) ? rendDate($enreg["DATE_FIN"], 0) : ''; $enreg["ID_SITE"]=$this->id_bib; $enreg["LOGIN"]=$enreg["IDABON"]; - if(!$enreg["ORDREABON"]) $enreg["ORDREABON"]=1; $enreg["ROLE"]="abonne_sigb"; $enreg["ROLE_LEVEL"]=2; $enreg["STATUT"]=0; + return $enreg; + } - // Ecrire - $id_user=fetchOne("select ID_USER from bib_admin_users where LOGIN='".$enreg["LOGIN"]."' and ID_SITE=".$this->id_bib); - if(!$id_user) sqlInsert("bib_admin_users",$enreg); - else sqlUpdate("update bib_admin_users set @SET@ where ID_USER=$id_user",$enreg); + + protected function saveOrUpdateInDB($data){ + $user = Class_Users::findFirstBy( + ['login'=>$data["LOGIN"], + 'id_site'=>$data['ID_SITE']]); + + if(!$user) + $user= new Class_Users(); + + $user + ->updateAttributes($data) + ->save(); + } + + // ---------------------------------------------------------------- // Transformation des accents @@ -137,14 +169,14 @@ class abonne { if(!trim($chaine)) return $chaine; switch($this->type_accents) - { + { case 2: // Windows return utf8_encode($chaine); case 3: // Dos for($i=0; $i < strlen($chaine); $i++) $new.=$this->dosDecode($chaine[$i]); return utf8_encode($new); default: return $chaine; - } + } } // ---------------------------------------------------------------- @@ -153,7 +185,7 @@ class abonne private function dosDecode($char) { switch($char) - { + { case 0xe9: $result = 'é'; break ; case 0xe8: $result = 'è'; break ; case 0xeb: $result = 'ë'; break ; @@ -172,7 +204,7 @@ class abonne case 0xe7: $result = 'ç'; break ; case 0xc7: $result = 'Ç'; break ; default: $result = $char; break; - } + } return $result; } diff --git a/cosmogramme/php/classes/classe_codif_langue.php b/cosmogramme/php/classes/classe_codif_langue.php index 8a77dd5296af8fe0d8cd81ebc619f001ca4d9509..4ff55e1c445435ff8f582a0780cd5f3ec52a213b 100644 --- a/cosmogramme/php/classes/classe_codif_langue.php +++ b/cosmogramme/php/classes/classe_codif_langue.php @@ -21,7 +21,6 @@ require_once('classe_codif_abstract.php'); class codif_langue extends codif_abstract { - use trait_singleton; protected $_table_name = 'codif_langue'; protected $_primary_key = 'id_langue'; diff --git a/cosmogramme/php/classes/classe_codif_matiere.php b/cosmogramme/php/classes/classe_codif_matiere.php index cf1950f88d35c73a44af0f80c9db0321e42634a8..2ad2a8946dc5e14208f2fa3450eb128ce5b0c6dd 100644 --- a/cosmogramme/php/classes/classe_codif_matiere.php +++ b/cosmogramme/php/classes/classe_codif_matiere.php @@ -21,7 +21,6 @@ require_once('classe_codif_abstract.php'); class codif_matiere extends codif_abstract{ - use trait_singleton; protected $_table_name = 'codif_matiere'; protected $_primary_key = 'id_matiere'; diff --git a/cosmogramme/php/classes/classe_iso2709.php b/cosmogramme/php/classes/classe_iso2709.php index 14448a22e13d7e0cfbf3b5172ad70f08729f282a..70c2157ef4053996d8494c01bc35ef7992cc119b 100644 --- a/cosmogramme/php/classes/classe_iso2709.php +++ b/cosmogramme/php/classes/classe_iso2709.php @@ -439,6 +439,8 @@ class iso2709_record { public function update($export_accents = false) { // supprime les lignes vides d'inner_data + $data= ''; + $inner_data_old = array_filter($this->inner_data); $this->inner_data = []; $this->inner_directory = []; diff --git a/cosmogramme/tests/bootstrap.php b/cosmogramme/tests/bootstrap.php index b18b827f697a606403e1d508d3dc28b7990ff581..ea78502a27d1461c70e4dd932ee092d179a80a7d 100644 --- a/cosmogramme/tests/bootstrap.php +++ b/cosmogramme/tests/bootstrap.php @@ -1,7 +1,7 @@ <?php -//error_reporting(E_ALL^E_DEPRECATED); -error_reporting(E_ERROR | E_PARSE | E_COMPILE_ERROR); +//error_reporting(E_ALL^E_DEPRECATED ^E_WARNING); +xberror_reporting(E_ERROR | E_PARSE | E_COMPILE_ERROR); ini_set('display_startup_errors', 1); ini_set('display_errors', 1); diff --git a/tests/application/modules/opac/controllers/AbonneControllerNewslettersTest.php b/tests/application/modules/opac/controllers/AbonneControllerNewslettersTest.php index 88a4672630fa37d9ffc46ff9f6ba8031a99cec5c..00564bae2bc13a75671deb945bd6f6a919e5a858 100644 --- a/tests/application/modules/opac/controllers/AbonneControllerNewslettersTest.php +++ b/tests/application/modules/opac/controllers/AbonneControllerNewslettersTest.php @@ -517,4 +517,5 @@ class AbonneControllerNewslettersValidationsTest extends AbonneControllerWithTwo } } + ?> \ No newline at end of file