Пример #1
0
 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);
                 }
             }
         }
     }
 }
Пример #2
0
 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;
 }
Пример #3
0
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;
}