[815] | 1 | <?php |
---|
| 2 | // +-------------------------------------------------+ |
---|
| 3 | // © 2002-2004 PMB Services / www.sigb.net pmb@sigb.net et contributeurs (voir www.sigb.net) |
---|
| 4 | // +-------------------------------------------------+ |
---|
| 5 | // $Id: export_z3950.php,v 1.11 2015-04-03 11:16:22 jpermanne Exp $ |
---|
| 6 | |
---|
| 7 | $base_path="../.."; |
---|
| 8 | |
---|
| 9 | $base_nocheck=1; |
---|
| 10 | $base_noheader=1; |
---|
| 11 | $base_nobody=1; |
---|
| 12 | $base_nosession=1; |
---|
| 13 | |
---|
| 14 | include($base_path."/includes/init.inc.php"); |
---|
| 15 | include($base_path."/admin/convert/export.class.php"); |
---|
| 16 | include($base_path."/admin/convert/xml_unimarc.class.php"); |
---|
| 17 | require_once($base_path."/includes/isbn.inc.php"); |
---|
| 18 | |
---|
| 19 | function make_error($nerr,$err_message) { |
---|
| 20 | echo $nerr."@".$err_message."@"; |
---|
| 21 | exit(); |
---|
| 22 | } |
---|
| 23 | |
---|
| 24 | if (!@pmb_mysql_connect(SQL_SERVER,USER_NAME,USER_PASS)) make_error(1,"Could'nt connect to database server"); |
---|
| 25 | if (!@pmb_mysql_select_db(DATA_BASE)) make_error(2,"Database unknown"); |
---|
| 26 | |
---|
| 27 | //Commande envoyée |
---|
| 28 | $command=$_GET["command"]; |
---|
| 29 | //Requete |
---|
| 30 | $query=$_GET["query"]; |
---|
| 31 | function construct_query($query,$not,$level,$argn="") { |
---|
| 32 | //La requête commence-t-elle par and, or ou and not ? |
---|
| 33 | $pos=strpos($query,"and not"); |
---|
| 34 | if (($pos!==false)&&($pos==0)) { |
---|
| 35 | $ope="and not"; |
---|
| 36 | } else { |
---|
| 37 | $pos=strpos($query,"or"); |
---|
| 38 | if (($pos!==false)&&($pos==0)) { |
---|
| 39 | $ope="or"; |
---|
| 40 | } else { |
---|
| 41 | $pos=strpos($query,"and"); |
---|
| 42 | if (($pos!==false)&&($pos==0)) { |
---|
| 43 | $ope="and"; |
---|
| 44 | } else $ope=""; |
---|
| 45 | } |
---|
| 46 | } |
---|
| 47 | if ($ope!="") { |
---|
| 48 | //Si opérateur, recherche des arguments |
---|
| 49 | $arqs=array(); |
---|
| 50 | preg_match("/^".$ope." arg".$level."!1\((.*)\) arg".$level."!2\((.*)\)$/",$query,$args); |
---|
| 51 | $return1=construct_query($args[1],0,$level+1,1); |
---|
| 52 | if ($ope=="and not") |
---|
| 53 | $return2=construct_query($args[2],1,$level+1,2); |
---|
| 54 | else |
---|
| 55 | $return2=construct_query($args[2],0,$level+1,2); |
---|
| 56 | if ($ope=="and not") $ope="and"; |
---|
| 57 | $requete="create temporary table r$level ENGINE=MyISAM "; |
---|
| 58 | if ($ope=="and") { |
---|
| 59 | $requete.="select distinct $return1.notice_id from $return1, $return2 where $return1.notice_id=$return2.notice_id"; |
---|
| 60 | @pmb_mysql_query($requete); |
---|
| 61 | } else { |
---|
| 62 | $requete.="select distinct notice_id from $return1"; |
---|
| 63 | @pmb_mysql_query($requete); |
---|
| 64 | $requete="insert into r$level select distinct notice_id from $return2 "; |
---|
| 65 | @pmb_mysql_query($requete); |
---|
| 66 | } |
---|
| 67 | $return="r$level"; |
---|
| 68 | } else { |
---|
| 69 | $use=explode("=",$query); |
---|
| 70 | switch ($use[0]) { |
---|
| 71 | //Titre |
---|
| 72 | case 4: |
---|
| 73 | if ($not) |
---|
| 74 | $requete="select distinct notice_id from notices where (index_wew not like '%".$use[1]."%' )"; |
---|
| 75 | else |
---|
| 76 | $requete="select distinct notice_id from notices where (index_wew like '%".$use[1]."%' )"; |
---|
| 77 | break; |
---|
| 78 | //ISBN |
---|
| 79 | case 7: |
---|
| 80 | if(isISBN($use[1])) { |
---|
| 81 | // si la saisie est un ISBN |
---|
| 82 | $code = formatISBN($use[1]); |
---|
| 83 | // si échec, ISBN erroné on le prend sous cette forme |
---|
| 84 | if(!$code) $code = $use[1]; |
---|
| 85 | } else $code = $use[1]; |
---|
| 86 | if ($not) |
---|
| 87 | $requete="select notice_id from notices where (code!='".$code."')"; |
---|
| 88 | else |
---|
| 89 | $requete="select notice_id from notices where (code='".$code."')"; |
---|
| 90 | break; |
---|
| 91 | // Auteur |
---|
| 92 | case 1003: |
---|
| 93 | if ($not) { |
---|
| 94 | $requete="create temporary table aut ENGINE=MyISAM select distinct responsability.responsability_notice as notice_id, index_author as auth from authors, responsability where responsability_author = author_id "; |
---|
| 95 | @pmb_mysql_query($requete); |
---|
| 96 | $requete="select distinct notice_id from aut where auth not like '%".$use[1]."%'"; |
---|
| 97 | } |
---|
| 98 | else |
---|
| 99 | $requete="select distinct notice_id from responsability, authors, notices where index_author like '%".$use[1]."%' and author_id=responsability_author and notice_id=responsability_notice "; |
---|
| 100 | break; |
---|
| 101 | default: |
---|
| 102 | make_error(3,"1=".$use[0]); |
---|
| 103 | break; |
---|
| 104 | } |
---|
| 105 | $requete="create temporary table r".$level."_".$argn." ENGINE=MyISAM ".$requete; |
---|
| 106 | @pmb_mysql_query($requete); |
---|
| 107 | $return="r".$level."_".$argn; |
---|
| 108 | } |
---|
| 109 | return $return; |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | switch ($command) { |
---|
| 113 | case "search": |
---|
| 114 | $sup_tables=""; |
---|
| 115 | $sql_query=construct_query($query,0,0); |
---|
| 116 | $sql_query="select notice_id from $sql_query limit 100"; |
---|
| 117 | $resultat=@pmb_mysql_query($sql_query); |
---|
| 118 | echo "0@No errors@"; |
---|
| 119 | echo @pmb_mysql_num_rows($resultat); |
---|
| 120 | while (list($id)=@pmb_mysql_fetch_row($resultat)) { |
---|
| 121 | echo "@$id"; |
---|
| 122 | } |
---|
| 123 | break; |
---|
| 124 | case "get_notice": |
---|
| 125 | $id=$query; |
---|
| 126 | $e = new export(array($id)); |
---|
| 127 | $e -> get_next_notice(); |
---|
| 128 | $toiso = new xml_unimarc(); |
---|
| 129 | $toiso->XMLtoiso2709_notice($e->notice); |
---|
| 130 | echo "0@No errors@"; |
---|
| 131 | echo $toiso->notices_[0]; |
---|
| 132 | break; |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | ?> |
---|