function maj_entrepot($source_id, $callback_progress = "", $recover = false, $recover_env = "") { global $dbh, $base_path, $file_in, $suffix, $converted, $origine, $charset, $outputtype; //Allons chercher plein d'informations utiles et amusantes $params = $this->get_source_params($source_id); $this->fetch_global_properties(); if ($params["PARAMETERS"]) { //Affichage du formulaire avec $params["PARAMETERS"] $vars = unserialize($params["PARAMETERS"]); foreach ($vars as $key => $val) { global ${$key}; ${$key} = $val; } } if (!isset($xslt_exemplaire)) { $xslt_exemplaire = ""; } $file_type = "iso_2709"; //Récupérons le nom du fichier if ($converted) { //Fichier converti $f = explode(".", $file_in); if (count($f) > 1) { unset($f[count($f) - 1]); } $final_file = implode(".", $f) . "." . $suffix . "~"; $final_file = "{$base_path}/temp/" . $final_file; $file_type = $outputtype; } else { $final_file = "{$base_path}/temp/" . $file_in; $file_type = $outputtype; } /* * ISO-2709 * */ if ($file_type == "iso_2709") { //Chargeons ces notices dans la base $this->loadfile_in_table_unimarc($final_file, $origine); $import_marc_count = "SELECT count(*) FROM import_marc"; $count_total = pmb_mysql_result(pmb_mysql_query($import_marc_count, $dbh), 0, 0); if (!$count_total) { return 0; } $count_lu = 0; $latest_percent = floor(100 * $count_lu / $count_total); //Et c'est parti $import_sql = "SELECT id_import, notice FROM import_marc WHERE origine = " . $origine; $res = pmb_mysql_query($import_sql); while ($row = pmb_mysql_fetch_assoc($res)) { $xmlunimarc = new xml_unimarc(); $nxml = $xmlunimarc->iso2709toXML_notice($row["notice"]); $xmlunimarc->notices_xml_[0] = '<?xml version="1.0" encoding="' . $charset . '"?>' . $xmlunimarc->notices_xml_[0]; if ($xslt_exemplaire) { $xmlunimarc->notices_xml_[0] = $this->apply_xsl_to_xml($xmlunimarc->notices_xml_[0], $xslt_exemplaire["content"]); } if ($nxml == 1) { $params = _parser_text_no_function_($xmlunimarc->notices_xml_[0], "NOTICE"); $this->rec_record($params, $source_id, 0); $count_lu++; } $sql_delete = "DELETE FROM import_marc WHERE id_import = " . $row['id_import']; @pmb_mysql_query($sql_delete); if (floor(100 * $count_lu / $count_total) > $latest_percent) { //Mise à jour de source_sync pour reprise en cas d'erreur /* $envt["current_origine"]=$origine; $envt["already_read_count"]=$count_lu; $requete="update source_sync set env='".addslashes(serialize($envt))."' where source_id=".$source_id; pmb_mysql_query($requete);*/ //Inform call_user_func($callback_progress, $count_lu / $count_total, $count_lu, $count_total); // $callback_progress($count_lu / $count_total, $count_lu, $count_total); $latest_percent = floor(100 * $count_lu / $count_total); flush(); ob_flush(); } } } else { if ($file_type == "xml") { //Chargeons ces notices dans la base $this->loadfile_in_table_xml($final_file, $origine); $import_marc_count = "SELECT count(*) FROM import_marc"; $count_total = pmb_mysql_result(pmb_mysql_query($import_marc_count, $dbh), 0, 0); if (!$count_total) { return 0; } $count_lu = 0; $latest_percent = floor(100 * $count_lu / $count_total); //Et c'est parti $import_sql = "SELECT id_import, notice FROM import_marc WHERE origine = " . $origine; $res = pmb_mysql_query($import_sql); while ($row = pmb_mysql_fetch_assoc($res)) { $xmlunimarc = '<?xml version="1.0" encoding="' . $charset . '"?>' . $row["notice"]; if ($xslt_exemplaire) { $xmlunimarc = $this->apply_xsl_to_xml($xmlunimarc, $xslt_exemplaire["content"]); } $params = _parser_text_no_function_($xmlunimarc, "NOTICE"); $this->rec_record($params, $source_id, 0); $count_lu++; $sql_delete = "DELETE FROM import_marc WHERE id_import = " . $row['id_import']; @pmb_mysql_query($sql_delete); if (floor(100 * $count_lu / $count_total) > $latest_percent) { //Mise à jour de source_sync pour reprise en cas d'erreur /* $envt["current_origine"]=$origine; $envt["already_read_count"]=$count_lu; $requete="update source_sync set env='".addslashes(serialize($envt))."' where source_id=".$source_id; pmb_mysql_query($requete);*/ //Inform call_user_func($callback_progress, $count_lu / $count_total, $count_lu, $count_total); // $callback_progress($count_lu / $count_total, $count_lu, $count_total); $latest_percent = floor(100 * $count_lu / $count_total); flush(); ob_flush(); } } } } return $count_lu; }
function search($source_id, $query, $search_id) { global $base_path, $charset, $include_path; //global $url,$z3950_base,$z3950_login,$z3950_password,$z3950_max_notices,$z3950_format,$z3950_port,$z3950_convert,$z3950_profil; $this->error = false; $this->error_message = ""; $params = $this->get_source_params($source_id); $this->fetch_global_properties(); if ($params["PARAMETERS"]) { //Affichage du formulaire avec $params["PARAMETERS"] $vars = unserialize($params["PARAMETERS"]); foreach ($vars as $key => $val) { global ${$key}; ${$key} = $val; } } if (!($z3950_max_notices * 1)) { $z3950_max_notices = 100; } //Tranformation de la recherche en requete rpn bib1 $rpn = $this->parse_query($query); $zurl = $url . ($z3950_port ? ":" . $z3950_port : "") . ($z3950_base ? "/" . $z3950_base : ""); $opts = array(); if ($z3950_login) { $opts["user"] = $z3950_login; } if ($z3950_password) { $opts["password"] = $z3950_password; } $opts["piggyback"] = false; $yaz_id = yaz_connect($zurl, $opts); yaz_element($yaz_id, "F"); yaz_range($yaz_id, 1, $z3950_max_notices); yaz_syntax($yaz_id, strtolower($z3950_format)); yaz_search($yaz_id, "rpn", $rpn . " "); $opts_wait = array("timeout" => $params["TIMEOUT"]); yaz_wait($opts_wait); if (yaz_error($yaz_id)) { $this->error = true; $this->error_message = yaz_error($yaz_id); } else { $n_results = yaz_hits($yaz_id); if ($n_results > $z3950_max_notices) { $n_results = $z3950_max_notices; } $convert_order = $this->get_convert_order($z3950_convert); for ($k = 1; $k <= $n_results; $k++) { $notice = yaz_record($yaz_id, $k, "raw"); //Conversion de la notice if ($z3950_convert) { $export = new convert($notice, $convert_order); if (!$export->error) { $cnotice = $export->output_notice; } else { $cnotice = ""; } } else { $cnotice = $notice; } if ($cnotice) { //Conversion de la notice en XML $xmlunimarc = new xml_unimarc(); $nxml = $xmlunimarc->iso2709toXML_notice($cnotice); if ($xmlunimarc->is_utf8) { $rcharset = "utf-8"; } else { $rcharset = $charset; } $xmlunimarc->notices_xml_[0] = '<?xml version="1.0" encoding="' . $rcharset . '"?>' . $xmlunimarc->notices_xml_[0]; if ($xslt_exemplaire) { $xmlunimarc->notices_xml_[0] = $this->apply_xsl_to_xml($xmlunimarc->notices_xml_[0], $xslt_exemplaire["content"]); } // print_r($xmlunimarc->notices_xml_[0]); if ($nxml >= 1) { $params = _parser_text_no_function_($xmlunimarc->notices_xml_[0], "NOTICE"); $this->rec_record($params, $source_id, $search_id); } } } } }
function get_notice_externe($notice_id) { global $charset, $msg; $memo = array(); $notice_extern_to_memo = array(); $notice_uni = $this->info['notice_base']; $req = "select * from notices where notice_id=" . $notice_id . " "; $resultat = pmb_mysql_query($req); if ($r = pmb_mysql_fetch_object($resultat)) { $code = $r->code; $notice_extern = $this->info['harvest']->havest_notice($code, $notice_id); // printr($notice_extern); // printr($notice_uni); $cpt = 0; foreach ($notice_extern as $contens) { $cpt++; $profil = $this->info['profil']->info['fields'][$contens['xml_id']]; // $pmb_fields=$this->info['harvest']->fields_id[$contens['xml_id']]; //printr($pmb_fields); $harvest = $this->info['harvest']->info['fields'][$contens['xml_id']]; if ($profil) { if ($profil['flagtodo'] == 1) { // on remplace les champs par les nouvelles valeurs foreach ($notice_uni['f'] as $index => $uni_field) { // printr($contens); // printr($uni_field); if ($contens['pmb_unimacfield'] && $uni_field['c'] == $contens['pmb_unimacfield'] && $contens['pmb_unimacsubfield']) { // si champ et sous champ, on delete les anciens champs/sous-champ foreach ($uni_field['s'] as $cpt => $ss_field) { if ($ss_field['c'] == $contens['pmb_unimacsubfield']) { array_splice($notice_uni['f'][$index]['s'], $cpt, 1); } } if (!count($uni_field['s'])) { array_splice($notice_uni['f'], $index, 1); } } elseif ($contens['pmb_unimacfield'] && $uni_field['c'] == $contens['pmb_unimacfield']) { // si pas de sous champ on efface tout array_splice($notice_uni['f'], $index, 1); } } } if ($profil['flagtodo'] == 1 || $profil['flagtodo'] == 2) { $notice_extern_to_memo[] = $contens; } } } //printr($notice_uni); //printr($notice_extern_to_memo); // Pour tout les champs nouveau à insérer $memo_prev = array(); foreach ($notice_extern_to_memo as $contens) { $nb = count($notice_uni['f']); $flag_create_unimacfield = 0; if ($contens['num_source'] != $memo_prev['num_source']) { $flag_create_unimacfield = 1; } if ($contens['pmb_unimacfield'] != $memo_prev['pmb_unimacfield']) { $flag_create_unimacfield = 1; } if ($contens['field_order'] != $memo_prev['field_order']) { $flag_create_unimacfield = 1; } if ($flag_create_unimacfield) { $index = $nb; } else { $index = $memo_prev['i']; } $notice_uni['f'][$index]['c'] = $contens['pmb_unimacfield']; $notice_uni['f'][$index]['ind'] = $contens['field_ind']; if ($contens['pmb_unimacsubfield']) { $sschamp = $contens['pmb_unimacsubfield']; } else { $sschamp = $contens['usubfield']; } $nb_ss = count($notice_uni['f'][$index]['s']); $notice_uni['f'][$index]['s'][$nb_ss]['c'] = $sschamp; $notice_uni['f'][$index]['s'][$nb_ss]['value'] = $contens['value']; $memo_prev = $contens; $memo_prev['i'] = $index; // $memo de l'enregistrement en cours // printr($memo_prev); } } else { //notice inexistante return ""; } // printr($notice_uni); // conversion du tableau en xml $export = new export($notice_id); $export->xml_array = $notice_uni; $export->toxml(); $notice_xml = $export->notice; // conversion du xml en unimarc $xml_unimarc = new xml_unimarc(); $xml_unimarc->XMLtoiso2709_notice($notice_xml, $charset); $notice = $xml_unimarc->notices_[0]; $z = new z3950_notice("unimarc", $notice); $z->libelle_form = $msg["notice_connecteur_remplace_catal"]; if ($z->bibliographic_level == "a" && $z->hierarchic_level == "2") { // article //$form=$z->get_form("catalog.php?categ=update&id=".$notice_id,$notice_id,'button',true); } else { $form = $z->get_form("catalog.php?categ=harvest&action=record¬ice_id=" . $notice_id, $notice_id, 'button'); } $form = str_replace("<!--!!form_title!!-->", "<h3>" . sprintf($msg["harvest_notice_build_title"], $notice_id, $item) . "</h3>", $form); print $form; }
${$op} = $corresp_op[$use[0]]; return $idf; } } return; } switch ($command) { case "search": //print $query."<br />"; construct_query($query, 0, 0); $s = new search(); $table = $s->make_search(); //print $s->make_human_query(); $sql_query = "select notice_id from {$table} limit 100"; $resultat = @mysql_query($sql_query); echo "0@No errors@"; echo @mysql_num_rows($resultat); while (list($id) = @mysql_fetch_row($resultat)) { echo "@{$id}"; } break; case "get_notice": $id = $query; $e = new export(array($id)); $e->get_next_notice(); $toiso = new xml_unimarc(); $toiso->XMLtoiso2709_notice($e->notice); echo "0@No errors@"; echo $toiso->notices_[0]; break; }
function isotoxml($notice, $s, $islast, $isfirst, $param_path) { global $charset; global $output_params; $i2x = new xml_unimarc(); $i2x->iso2709toXML_notice($notice, $s['FORMAT']); if ($i2x->n_valid == 0) { $r['VALID'] = false; $r['DATA'] = ""; $r['ERROR'] = $i2x->error_msg[0]; } else { $r['VALID'] = true; $r['DATA'] = $i2x->notices_xml_[0]; $r['ERROR'] = ""; //Si ce n'est pas la dernière transformation, on rajoute des tags root et l'entête if (!$islast) { $r['DATA'] = "<" . $s['TROOTELEMENT'][0]['value'] . ">\n" . $r['DATA']; $r['DATA'] .= "</" . $s['TROOTELEMENT'][0]['value'] . ">"; $r['DATA'] = "<?xml version=\"1.0\" encoding=\"" . ($i2x->is_utf8 ? "utf-8" : $charset) . "\" ?>\n" . $r['DATA']; } } return $r; }