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_new.php,v 1.7 2015-04-03 11:16:22 jpermanne Exp $ |
---|
6 | |
---|
7 | $base_path="../.."; |
---|
8 | |
---|
9 | $base_noheader = 1; |
---|
10 | $base_nocheck = 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."/classes/search.class.php"); |
---|
18 | require_once($base_path."/includes/isbn.inc.php"); |
---|
19 | |
---|
20 | $corresp=array( |
---|
21 | "1016"=> "42", //Tous les champs |
---|
22 | "4"=> "1", // titre |
---|
23 | "1003"=> "2", // auteur |
---|
24 | "1018"=> "3", // editeur |
---|
25 | "31"=> "23", // année d'édition |
---|
26 | "5"=> "4", // collection |
---|
27 | "7"=> "22", // ISBN |
---|
28 | "8"=> "22", // ISSN |
---|
29 | "21"=> "13" // Mots clés |
---|
30 | ); |
---|
31 | |
---|
32 | $corresp_op=array( |
---|
33 | "1016"=> "BOOLEAN", |
---|
34 | "4"=> "BOOLEAN", |
---|
35 | "1003"=> "BOOLEAN", |
---|
36 | "1018"=> "BOOLEAN", |
---|
37 | "31"=> "CONTAINS_AT_LEAST", |
---|
38 | "5"=> "BOOLEAN", |
---|
39 | "7"=> "STARTWITH", |
---|
40 | "8"=> "STARTWITH", |
---|
41 | //"21"=> "11", |
---|
42 | "21"=> "BOOLEAN" |
---|
43 | ); |
---|
44 | function make_error($nerr,$err_message) { |
---|
45 | echo $nerr."@".$err_message."@"; |
---|
46 | exit(); |
---|
47 | } |
---|
48 | |
---|
49 | if (!@pmb_mysql_connect(SQL_SERVER,USER_NAME,USER_PASS)) make_error(1,"Could'nt connect to database server"); |
---|
50 | if (!@pmb_mysql_select_db(DATA_BASE)) make_error(2,"Database unknown"); |
---|
51 | |
---|
52 | //Commande envoyée |
---|
53 | $command=$_GET["command"]; |
---|
54 | //Requete |
---|
55 | $query=$_GET["query"]; |
---|
56 | |
---|
57 | function traite_val($value,$idf) { |
---|
58 | switch ($idf) { |
---|
59 | case "22": |
---|
60 | if(isISBN($value)) { |
---|
61 | // si la saisie est un ISBN |
---|
62 | $code = formatISBN($value); |
---|
63 | // si échec, ISBN erroné on le prend sous cette forme |
---|
64 | if(!$code) $code = $value; |
---|
65 | } else $code = $value; |
---|
66 | $ret=$code; |
---|
67 | break; |
---|
68 | default: |
---|
69 | $ret=$value; |
---|
70 | break; |
---|
71 | } |
---|
72 | return $ret; |
---|
73 | } |
---|
74 | |
---|
75 | function construct_query($query,$not,$level,$argn="",$oper="") { |
---|
76 | global $corresp,$search,$corresp_op; |
---|
77 | //La requête commence-t-elle par and, or ou and not ? |
---|
78 | $pos=strpos($query,"and not"); |
---|
79 | if (($pos!==false)&&($pos==0)) { |
---|
80 | $ope="ex"; |
---|
81 | } else { |
---|
82 | $pos=strpos($query,"or"); |
---|
83 | if (($pos!==false)&&($pos==0)) { |
---|
84 | $ope="or"; |
---|
85 | } else { |
---|
86 | $pos=strpos($query,"and"); |
---|
87 | if (($pos!==false)&&($pos==0)) { |
---|
88 | $ope="and"; |
---|
89 | } else $ope=""; |
---|
90 | } |
---|
91 | } |
---|
92 | |
---|
93 | if ($ope!="") { |
---|
94 | //Si opérateur, recherche des arguments |
---|
95 | $arqs=array(); |
---|
96 | preg_match("/^".($ope=="ex"?"and not":$ope)." arg".$level."!1\((.*)\) arg".$level."!2\((.*)\)$/",$query,$args); |
---|
97 | //print "/^".$ope." arg".$level."!1\((.*)\) arg".$level."!2\((.*)\)$/"; |
---|
98 | //print_r($args); |
---|
99 | $return1=construct_query($args[1],0,$level+1,1,$ope); |
---|
100 | if (($oper)&&($return1)) { |
---|
101 | $inter="inter_".($level-2+$argn)."_f_".$return1; |
---|
102 | global $$inter; |
---|
103 | if (!$$inter) |
---|
104 | $$inter=$oper; |
---|
105 | //print $inter."=".$$inter."<br />"; |
---|
106 | } |
---|
107 | $return2=construct_query($args[2],0,$level+1,2,$ope); |
---|
108 | if ($return2) { |
---|
109 | //print $level." ".$argn; |
---|
110 | if ($argn=="") $argn=2; |
---|
111 | $inter="inter_".($level-1+$argn)."_f_".$return2; |
---|
112 | global $$inter; |
---|
113 | if (!$$inter) |
---|
114 | $$inter=$ope; |
---|
115 | //print $inter."=".$$inter."<br />"; |
---|
116 | } |
---|
117 | return; |
---|
118 | } else { |
---|
119 | $use=explode("=",$query); |
---|
120 | $idf=$corresp[$use[0]]; |
---|
121 | if (!$idf) |
---|
122 | make_error(3,"1=".$use[0]); |
---|
123 | else { |
---|
124 | $search[]="f_".$idf; |
---|
125 | $vals=array(); |
---|
126 | $vals[0]=traite_val($use[1],$idf); |
---|
127 | $field="field_".(!$level?0:($level-2+$argn))."_f_".$idf; |
---|
128 | global $$field; |
---|
129 | $$field=$vals; |
---|
130 | $op="op_".(!$level?0:($level-2+$argn))."_f_".$idf; |
---|
131 | global $$op; |
---|
132 | $$op=$corresp_op[$use[0]]; |
---|
133 | return $idf; |
---|
134 | } |
---|
135 | } |
---|
136 | return; |
---|
137 | } |
---|
138 | |
---|
139 | switch ($command) { |
---|
140 | case "search": |
---|
141 | //print $query."<br />"; |
---|
142 | construct_query($query,0,0); |
---|
143 | $s=new search(); |
---|
144 | $table=$s->make_search(); |
---|
145 | //print $s->make_human_query(); |
---|
146 | $sql_query="select notice_id from $table limit 100"; |
---|
147 | $resultat=@pmb_mysql_query($sql_query); |
---|
148 | echo "0@No errors@"; |
---|
149 | echo @pmb_mysql_num_rows($resultat); |
---|
150 | while (list($id)=@pmb_mysql_fetch_row($resultat)) { |
---|
151 | echo "@$id"; |
---|
152 | } |
---|
153 | break; |
---|
154 | case "get_notice": |
---|
155 | $id=$query; |
---|
156 | $e = new export(array($id)); |
---|
157 | $e -> get_next_notice(); |
---|
158 | $toiso = new xml_unimarc(); |
---|
159 | $toiso->XMLtoiso2709_notice($e->notice); |
---|
160 | echo "0@No errors@"; |
---|
161 | echo $toiso->notices_[0]; |
---|
162 | break; |
---|
163 | } |
---|
164 | |
---|
165 | ?> |
---|