=') && extension_loaded('xsl')) {
if (substr(phpversion(), 0, 1) == "5") @ini_set("zend.ze1_compatibility_mode", "0");
require_once($include_path.'/xslt-php4-to-php5.inc.php');
}
if (!function_exists('file_put_contents')) {
function file_put_contents($filename, $data) {
$f = @fopen($filename, 'w');
if (!$f) {
return false;
} else {
$bytes = fwrite($f, $data);
fclose($f);
return $bytes;
}
}
}
//Voici un array_unique qui marche aussi avec des objects et des arrays.
function array_unique_more($array, $keep_key_assoc = false)
{
$duplicate_keys = array();
$tmp = array();
foreach ($array as $key=>$val)
{
// convert objects to arrays, in_array() does not support objects
if (is_object($val))
$val = (array)$val;
if (!in_array($val, $tmp))
$tmp[] = $val;
else
$duplicate_keys[] = $key;
}
foreach ($duplicate_keys as $key)
unset($array[$key]);
return $keep_key_assoc ? $array : array_values($array);
}
class aligastore extends connector {
//Variables internes pour la progression de la récupération des notices
var $callback_progress; //Nom de la fonction de callback progression passée par l'appellant
var $current_set; //Set en cours de synchronisation
var $total_sets; //Nombre total de sets sélectionnés
var $metadata_prefix; //Préfixe du format de données courant
var $source_id; //Numéro de la source en cours de synchro
var $search_id;
var $xslt_transform; //Feuille xslt transmise
var $sets_names; //Nom des sets pour faire plus joli !!
var $del_old; //Supression ou non des notices dejà existantes
var $url;
var $username;
var $password;
var $blank_image;
var $image_thumb_url;
var $image_front;
var $image_back;
var $image_folder;
var $image_folder_url;
var $fetchimages;
//Résultat de la synchro
var $error; //Y-a-t-il eu une erreur
var $error_message; //Si oui, message correspondant
function aligastore($connector_path="") {
parent::connector($connector_path);
}
function get_id() {
return "aligastore";
}
//Est-ce un entrepot ?
function is_repository() {
return 3;
}
function unserialize_source_params($source_id) {
$params=$this->get_source_params($source_id);
if ($params["PARAMETERS"]) {
$vars=unserialize($params["PARAMETERS"]);
$params["PARAMETERS"]=$vars;
}
return $params;
}
function source_get_property_form($source_id) {
global $charset;
$params=$this->get_source_params($source_id);
if ($params["PARAMETERS"]) {
//Affichage du formulaire avec $params["PARAMETERS"]
$vars=unserialize($params["PARAMETERS"]);
foreach ($vars as $key=>$val) {
global $$key;
$$key=$val;
}
}
//URL
if (!isset($url))
$url = "http://www.aligastore.com/partenaires/xmldetaillivre.php";
$form="
";
//Username
if (!isset($username))
$username="";
$form.="
";
//Password
if (!isset($password))
$password="";
$form.="
";
//Image Thumb URL
if (!isset($image_thumb_url))
$image_thumb_url="http://www.aligastore.com/query.dll/img?gcdFab=!!isbn!!&type=0";
$form.="
";
//Image Front
if (!isset($image_front))
$image_front="http://www.aligastore.com/query.dll/img?gcdFab=!!isbn!!&type=1";
$form.="
";
//Image Back
if (!isset($image_back))
$image_back="http://www.aligastore.com/query.dll/img?gcdFab=!!isbn!!&type=4";
$form.="
";
//Image Fetch?
if (!isset($fetch_images))
$fetch_images=0;
$form.="
";
//Image Folder
if (!isset($image_folder))
$image_folder="";
$form.="
";
//Image Folder Public URL
if (!isset($image_folder_public))
$image_folder_public="";
$form.="
";
$form.="
";
return $form;
}
function make_serialized_source_properties($source_id) {
global $url,$username, $password, $fetch_images, $image_folder, $image_thumb_url, $image_front, $image_back, $image_folder_public;
$t["url"]=stripslashes($url);
$t["username"]=stripslashes($username);
$t["password"]=stripslashes($password);
$t["fetch_images"]=stripslashes($fetch_images);
$t["image_folder"]=stripslashes($image_folder);
$t["image_folder_public"]=stripslashes($image_folder_public);
$t["image_thumb_url"]=stripslashes($image_thumb_url);
$t["image_front"]=stripslashes($image_front);
$t["image_back"]=stripslashes($image_back);
$this->sources[$source_id]["PARAMETERS"]=serialize($t);
}
//Récupération des proriétés globales par défaut du connecteur (timeout, retry, repository, parameters)
function fetch_default_global_values() {
$this->timeout=5;
$this->repository=1;
$this->retry=3;
$this->ttl=1800;
$this->parameters="";
}
//Formulaire des propriétés générales
function get_property_form() {
$this->fetch_global_properties();
return "";
}
function make_serialized_properties() {
$this->parameters="";
}
function rec_record($record, $source_id, $search_id) {
global $charset,$base_path;
if (!trim($record))
return;
//On a un enregistrement unimarc, on l'enregistre
$rec_uni_dom=new xml_dom_aligastore($record,$charset, false);
if (!$rec_uni_dom->error) {
//Initialisation
$ref="";
$ufield="";
$usubfield="";
$field_order=0;
$subfield_order=0;
$value="";
$date_import=date("Y-m-d H:i:s",time());
$fs=$rec_uni_dom->get_nodes("unimarc/notice/f");
//Recherche du 001
if ($fs)
for ($i=0; $iget_datas($fs[$i]);
break;
}
}
if (!$ref) $ref = md5($record);
//Mise à jour
if ($ref) {
//Si conservation des anciennes notices, on regarde si elle existe
if (!$this->del_old) {
$requete="select count(*) from entrepot_source_".$source_id." where ref='".addslashes($ref)."'";
$rref=mysql_query($requete);
if ($rref) $ref_exists=mysql_result($rref,0,0);
}
//Si pas de conservation des anciennes notices, on supprime
if ($this->del_old) {
$requete="delete from entrepot_source_".$source_id." where ref='".addslashes($ref)."'";
mysql_query($requete);
}
$ref_exists = false;
//Si pas de conservation ou ref�rence inexistante
if (($this->del_old)||((!$this->del_old)&&(!$ref_exists))) {
//Insertion de l'ent�te
$n_header["rs"]=$rec_uni_dom->get_value("unimarc/notice/rs");
$n_header["ru"]=$rec_uni_dom->get_value("unimarc/notice/ru");
$n_header["el"]=$rec_uni_dom->get_value("unimarc/notice/el");
$n_header["bl"]=$rec_uni_dom->get_value("unimarc/notice/bl");
$n_header["hl"]=$rec_uni_dom->get_value("unimarc/notice/hl");
$n_header["dt"]=$rec_uni_dom->get_value("unimarc/notice/dt");
//R�cup�ration d'un ID
$requete="insert into external_count (recid, source_id) values('".addslashes($this->get_id()." ".$source_id." ".$ref)."', ".$source_id.")";
$rid=mysql_query($requete);
if ($rid) $recid=mysql_insert_id();
foreach($n_header as $hc=>$code) {
$requete="insert into entrepot_source_".$source_id." (connector_id,source_id,ref,date_import,ufield,usubfield,field_order,subfield_order,value,i_value,recid, search_id) values(
'".addslashes($this->get_id())."',".$source_id.",'".addslashes($ref)."','".addslashes($date_import)."',
'".$hc."','',-1,0,'".addslashes($code)."','',$recid, '$search_id')";
mysql_query($requete);
}
if ($fs)
for ($i=0; $iget_nodes("s",$fs[$i]);
if (is_array($ss)) {
for ($j=0; $jget_datas($ss[$j]);
$subfield_order=$j;
$requete="insert into entrepot_source_".$source_id." (connector_id,source_id,ref,date_import,ufield,usubfield,field_order,subfield_order,value,i_value,recid, search_id) values(
'".addslashes($this->get_id())."',".$source_id.",'".addslashes($ref)."','".addslashes($date_import)."',
'".addslashes($ufield)."','".addslashes($usubfield)."',".$field_order.",".$subfield_order.",'".addslashes($value)."',
' ".addslashes(strip_empty_words($value))." ',$recid, '$search_id')";
mysql_query($requete);
}
} else {
$value=$rec_uni_dom->get_datas($fs[$i]);
$requete="insert into entrepot_source_".$source_id." (connector_id,source_id,ref,date_import,ufield,usubfield,field_order,subfield_order,value,i_value,recid, search_id) values(
'".addslashes($this->get_id())."',".$source_id.",'".addslashes($ref)."','".addslashes($date_import)."',
'".addslashes($ufield)."','".addslashes($usubfield)."',".$field_order.",".$subfield_order.",'".addslashes($value)."',
' ".addslashes(strip_empty_words($value))." ',$recid, '$search_id')";
mysql_query($requete);
}
}
}
$this->n_recu++;
}
}
}
function cancel_maj($source_id) {
return false;
}
function break_maj($source_id) {
return false;
}
function form_pour_maj_entrepot($source_id,$sync_form="sync_form") {
global $quoi_synchro;
$form = "";
$form .= "";
$form .= $this->msg["aliga_syncbase"];
$form .= '