function import($data) { // cette méthode prend en entrée un tableau constitué des informations suivantes : // $data['statut_libelle'] // $data['pret_flag'] // $data['statusdoc_codage_import'] // $data['statusdoc_owner'] global $dbh; // check sur le type de la variable passée en paramètre if (!sizeof($data) || !is_array($data)) { // si ce n'est pas un tableau ou un tableau vide, on retourne 0 return 0; } // check sur les éléments du tableau $long_maxi = pmb_mysql_field_len(pmb_mysql_query("SELECT statut_libelle FROM docs_statut limit 1"), 0); $data['statut_libelle'] = rtrim(substr(preg_replace('/\\[|\\]/', '', rtrim(ltrim($data['statut_libelle']))), 0, $long_maxi)); $long_maxi = pmb_mysql_field_len(pmb_mysql_query("SELECT statusdoc_codage_import FROM docs_statut limit 1"), 0); $data['statusdoc_codage_import'] = rtrim(substr(preg_replace('/\\[|\\]/', '', rtrim(ltrim($data['statusdoc_codage_import']))), 0, $long_maxi)); if ($data['statusdoc_owner'] == "") { $data['statusdoc_owner'] = 0; } if ($data['statut_libelle'] == "") { return 0; } /* statusdoc_codage_import est obligatoire si statusdoc_owner != 0 */ if ($data['statusdoc_owner'] != 0 && $data['statusdoc_codage_import'] == "") { return 0; } // préparation de la requête $key0 = addslashes($data['statut_libelle']); $key1 = addslashes($data['statusdoc_codage_import']); $key2 = $data['statusdoc_owner']; /* vérification que le statut existe */ $query = "SELECT idstatut FROM docs_statut WHERE statusdoc_codage_import='{$key1}' and statusdoc_owner = '{$key2}' LIMIT 1 "; $result = @pmb_mysql_query($query, $dbh); if (!$result) { die("can't SELECT docs_statut " . $query); } $docs_statut = pmb_mysql_fetch_object($result); /* le statut de doc existe, on retourne l'ID */ if ($docs_statut->idstatut) { return $docs_statut->idstatut; } // id non-récupérée, il faut créer la forme. /* une petite valeur par défaut */ if ($data['pret_flag'] == "") { $data['pret_flag'] = 1; } $query = "INSERT INTO docs_statut SET "; $query .= "statut_libelle='" . $key0 . "', "; $query .= "pret_flag='" . $data['pret_flag'] . "', "; $query .= "statusdoc_codage_import='" . $key1 . "', "; $query .= "statusdoc_owner='" . $key2 . "' "; $result = @pmb_mysql_query($query, $dbh); if (!$result) { die("can't INSERT into docs_statut " . $query); } return pmb_mysql_insert_id($dbh); }
function import($data) { // cette méthode prend en entrée un tableau constitué des informations suivantes : // $data['section_libelle'] // $data['sdoc_codage_import'] // $data['sdoc_owner'] global $dbh; // check sur le type de la variable passée en paramètre if (!sizeof($data) || !is_array($data)) { // si ce n'est pas un tableau ou un tableau vide, on retourne 0 return 0; } // check sur les éléments du tableau $long_maxi = pmb_mysql_field_len(pmb_mysql_query("SELECT section_libelle FROM docs_section limit 1"), 0); $data['section_libelle'] = rtrim(substr(preg_replace('/\\[|\\]/', '', rtrim(ltrim($data['section_libelle']))), 0, $long_maxi)); $long_maxi = pmb_mysql_field_len(pmb_mysql_query("SELECT sdoc_codage_import FROM docs_section limit 1"), 0); $data['sdoc_codage_import'] = rtrim(substr(preg_replace('/\\[|\\]/', '', rtrim(ltrim($data['sdoc_codage_import']))), 0, $long_maxi)); if ($data['sdoc_owner'] == "") { $data['sdoc_owner'] = 0; } if ($data['section_libelle'] == "") { return 0; } /* sdoc_codage_import est obligatoire si sdoc_owner != 0 */ // if(($data['sdoc_owner']!=0) && ($data['sdoc_codage_import']=="")) return 0; // préparation de la requête $key0 = addslashes($data['section_libelle']); $key1 = addslashes($data['sdoc_codage_import']); $key2 = $data['sdoc_owner']; /* vérification que la section existe */ $query = "SELECT idsection FROM docs_section WHERE sdoc_codage_import='{$key1}' and sdoc_owner = '{$key2}' LIMIT 1 "; $result = @pmb_mysql_query($query, $dbh); if (!$result) { die("can't SELECT docs_section " . $query); } $docs_section = pmb_mysql_fetch_object($result); /* le type de doc existe, on retourne l'ID */ if ($docs_section->idsection) { return $docs_section->idsection; } // id non-récupérée, il faut créer la forme. $query = "INSERT INTO docs_section SET "; $query .= "section_libelle='" . $key0 . "', "; $query .= "sdoc_codage_import='" . $key1 . "', "; $query .= "sdoc_owner='" . $key2 . "' "; $result = @pmb_mysql_query($query, $dbh); if (!$result) { die("can't INSERT into docs_section " . $query); } $id_section_cree = pmb_mysql_insert_id($dbh); $query = "insert into docsloc_section (SELECT {$id_section_cree}, idlocation FROM docs_location) "; $result = @pmb_mysql_query($query, $dbh); return $id_section_cree; }
function import($data) { // cette méthode prend en entrée un tableau constitué des informations suivantes : // $data['nom'] // $data['pays'] // $data['diffusion'] global $dbh; // check sur le type de la variable passée en paramètre if (!sizeof($data) || !is_array($data)) { // si ce n'est pas un tableau ou un tableau vide, on retourne 0 return 0; } // check sur les éléments du tableau $long_maxi = pmb_mysql_field_len(pmb_mysql_query("SELECT orinot_nom FROM origine_notice "), 0); $data['nom'] = rtrim(substr(preg_replace('/\\[|\\]/', '', rtrim(ltrim($data['nom']))), 0, $long_maxi)); $long_maxi = pmb_mysql_field_len(pmb_mysql_query("SELECT orinot_pays FROM origine_notice "), 0); $data['pays'] = rtrim(substr(preg_replace('/\\[|\\]/', '', rtrim(ltrim($data['pays']))), 0, $long_maxi)); if ($data['diffusion'] == "") { $data['diffusion'] = 1; } if ($data['nom'] == "") { return 0; } // préparation de la requête $key0 = addslashes($data['nom']); $key1 = addslashes($data['pays']); $key2 = $data['diffusion']; /* vérification que le statut existe */ $query = "SELECT orinot_id FROM origine_notice WHERE orinot_nom='{$key0}' and orinot_pays = '{$key1}' LIMIT 1 "; $result = @pmb_mysql_query($query, $dbh); if (!$result) { die("can't SELECT origine_notice " . $query); } $origine_notice = pmb_mysql_fetch_object($result); /* le statut de doc existe, on retourne l'ID */ if ($origine_notice->orinot_id) { return $origine_notice->orinot_id; } // id non-récupérée, il faut créer la forme. $query = "INSERT INTO origine_notice SET "; $query .= "orinot_nom='" . $key0 . "', "; $query .= "orinot_pays='" . $key1 . "', "; $query .= "orinot_diffusion='" . $key2 . "' "; $result = @pmb_mysql_query($query, $dbh); if (!$result) { die("can't INSERT into origine_notice " . $query); } return pmb_mysql_insert_id($dbh); }
static function import($data) { // cette méthode prend en entrée un tableau constitué des informations éditeurs suivantes : // $data['name'] Nom de la collection // $data['parent'] id de l'éditeur parent de la collection // $data['issn'] numéro ISSN de la collection global $dbh; // check sur le type de la variable passée en paramètre if (!sizeof($data) || !is_array($data)) { // si ce n'est pas un tableau ou un tableau vide, on retourne 0 return 0; } // check sur les éléments du tableau (data['name'] est requis). $long_maxi_name = pmb_mysql_field_len(pmb_mysql_query("SELECT collection_name FROM collections limit 1"), 0); $data['name'] = rtrim(substr(preg_replace('/\\[|\\]/', '', rtrim(ltrim($data['name']))), 0, $long_maxi_name)); //si on a pas d'id, on peut avoir les infos de l'éditeur if (!$data['parent']) { if ($data['publisher']) { //on les a, on crée l'éditeur $data['parent'] = editeur::import($data['publisher']); } } if ($data['name'] == "" || $data['parent'] == 0) { /* il nous faut impérativement un éditeur */ return 0; } // préparation de la requête $key0 = addslashes($data['name']); $key1 = $data['parent']; $key2 = addslashes($data['issn']); /* vérification que l'éditeur existe bien ! */ $query = "SELECT ed_id FROM publishers WHERE ed_id='{$key1}' LIMIT 1 "; $result = @pmb_mysql_query($query, $dbh); if (!$result) { die("can't SELECT publishers " . $query); } if (pmb_mysql_num_rows($result) == 0) { return 0; } /* vérification que la collection existe */ $query = "SELECT collection_id FROM collections WHERE collection_name='{$key0}' AND collection_parent='{$key1}' LIMIT 1 "; $result = @pmb_mysql_query($query, $dbh); if (!$result) { die("can't SELECT collections " . $query); } $collection = pmb_mysql_fetch_object($result); /* la collection existe, on retourne l'ID */ if ($collection->collection_id) { return $collection->collection_id; } // id non-récupérée, il faut créer la forme. $query = 'INSERT INTO collections SET collection_name="' . $key0 . '", '; $query .= 'collection_parent="' . $key1 . '", '; $query .= 'collection_issn="' . $key2 . '", '; $query .= 'index_coll=" ' . strip_empty_words($key0) . ' ' . strip_empty_words($key2) . ' ", '; $query .= 'collection_comment = "' . addslashes($data['comment']) . '" '; $result = @pmb_mysql_query($query, $dbh); if (!$result) { die("can't INSERT into database"); } $id = pmb_mysql_insert_id($dbh); if ($data['subcollections']) { for ($i = 0; $i < count($data['subcollections']); $i++) { $subcoll = $data['subcollections'][$i]; $subcoll['coll_parent'] = $id; subcollection::import($subcoll); } } audit::insert_creation(AUDIT_COLLECTION, $id); //update authority informations $authority = new authority(0, $id, AUT_TABLE_COLLECTIONS); $authority->set_num_statut($data['statut']); $authority->update(); collection::update_index($id); return $id; }
function insert_in_database($addslashes = false) { global $dbh; global $class_path; global $gestion_acces_active, $gestion_acces_user_notice, $gestion_acces_empr_notice; global $res_prf, $chk_rights; global $pmb_synchro_rdf; global $opac_url_base, $pmb_notice_img_folder_id; if ($this->bibliographic_level == "s" && $this->hierarchic_level == "2") { $this->bibliographic_level = "b"; } $new_notice = 0; $notice_retour = 0; $long_maxi = pmb_mysql_field_len(pmb_mysql_query("SELECT code FROM notices limit 1"), 0); $isbn = rtrim(substr($this->isbn, 0, $long_maxi)); if ($isbn != "") { if (isISBN($isbn)) { if (strlen($isbn) == 13) { $isbn1 = formatISBN($isbn, 13); } else { $isbn1 = formatISBN($isbn, 10); } } $sql_rech = "select notice_id from notices where code = '" . $isbn . "' "; if ($isbn1) { $sql_rech .= " or code='" . $isbn1 . "' "; } $sql_result_rech = pmb_mysql_query($sql_rech) or die("Couldn't select notice ! = " . $sql_rech); if (pmb_mysql_num_rows($sql_result_rech) == 0) { $new_notice = 1; } else { $new_notice = 0; $lu = pmb_mysql_fetch_array($sql_result_rech); $notice_retour = $lu['notice_id']; } } else { $new_notice = 1; } if ($new_notice == 0) { $retour = array($new_notice, $notice_retour); return $retour; } for ($i = 0; $i < 2; $i++) { if ($this->editors[$i]['id']) { $editor_ids[$i] = $this->editors[$i]['id']; } else { $editor_ids[$i] = editeur::import($this->editors[$i]); } } $this->collection['parent'] = $editor_ids[0]; if ($this->collection["id"]) { $collection_id = $this->collection["id"]; } else { $collection_id = collection::import($this->collection); } $this->subcollection['coll_parent'] = $collection_id; if ($this->subcollection["id"]) { $subcollection_id = $this->subcollection["id"]; } else { $subcollection_id = subcollection::import($this->subcollection); } $serie_id = serie::import(stripslashes($this->serie)); /* traitement de Dewey */ if (!$this->internal_index) { if (!$this->dewey["new_comment"]) { $this->dewey["new_comment"] = ""; } if (!$this->dewey["new_pclass"]) { $this->dewey["new_pclass"] = ""; } $this->internal_index = indexint::import(clean_string($this->dewey[0]), clean_string($this->dewey["new_comment"]), clean_string($this->dewey["new_pclass"])); } $date_parution_z3950 = notice::get_date_parution($this->year); /* Origine de la notice */ $this->orinot_id = origine_notice::import($this->origine_notice); if ($this->orinot_id == 0) { $this->orinot_id = 1; } if ($addslashes) { $this->document_type = addslashes($this->document_type); $this->isbn = addslashes($this->isbn); $this->titles[0] = addslashes($this->titles[0]); $this->titles[1] = addslashes($this->titles[1]); $this->titles[2] = addslashes($this->titles[2]); $this->titles[3] = addslashes($this->titles[3]); $this->nbr_in_serie = addslashes($this->nbr_in_serie); $this->year = addslashes($this->year); $this->page_nbr = addslashes($this->page_nbr); $this->illustration = addslashes($this->illustration); $this->size = addslashes($this->size); $this->accompagnement = addslashes($this->accompagnement); $this->nbr_in_collection = addslashes($this->nbr_in_collection); $this->mention_edition = addslashes($this->mention_edition); $this->general_note = addslashes($this->general_note); $this->content_note = addslashes($this->content_note); $this->abstract_note = addslashes($this->abstract_note); $this->commentaire_gestion = addslashes($this->commentaire_gestion); $this->indexation_lang = addslashes($this->indexation_lang); $this->thumbnail_url = addslashes($this->thumbnail_url); $this->free_index = addslashes($this->free_index); $this->link_url = addslashes($this->link_url); $this->link_format = addslashes($this->link_format); $this->prix = addslashes($this->prix); //les oubliés du premier tour $serie_id = addslashes($serie_id); $this->bibliographic_level = addslashes($this->bibliographic_level); $this->hierarchic_level = addslashes($this->hierarchic_level); $date_parution_z3950 = addslashes($date_parution_z3950); } $sql_ins = "insert into notices (\n\t\t\ttypdoc ,\n\t\t\tcode \t,\n\t\t\ttit1 ,\n\t\t\ttit2 ,\n\t\t\ttit3 ,\n\t\t\ttit4 ,\n\t\t\ttparent_id ,\n\t\t\ttnvol ,\n\t\t\ted1_id ,\n\t\t\ted2_id ,\n\t\t\tyear ,\n\t\t\tnpages ,\n\t\t\till ,\n\t\t\tsize ,\n\t\t\taccomp ,\n\t\t\tcoll_id ,\n\t\t\tsubcoll_id ,\n\t\t\tnocoll ,\n\t\t\tmention_edition ,\n\t\t\tn_gen ,\n\t\t\tn_contenu ,\n\t\t\tn_resume ,\n\t\t\tindexint,\n\t\t\tstatut,\n\t\t\tcommentaire_gestion,\n\t\t\tsignature,\n\t\t\tthumbnail_url,\n\t\t\tindex_l,\n\t\t\tniveau_biblio,\n\t\t\tniveau_hierar,\n\t\t\tlien,\n\t\t\teformat,\n\t\t\torigine_catalogage,\n\t\t\tprix,\n\t\t\tcreate_date,\n\t\t\tdate_parution,\n\t\t\tindexation_lang\n\t\t\t) values (\n\t\t\t'" . $this->document_type . "',\t\n\t\t\t'" . $this->isbn . "',\t\n\t\t\t'" . $this->titles[0] . "',\n\t\t\t'" . $this->titles[1] . "',\n\t\t\t'" . $this->titles[2] . "',\n\t\t\t'" . $this->titles[3] . "',\n\t\t\t'" . $serie_id . "',\n\t\t\t'" . $this->nbr_in_serie . "',\n\t\t\t" . $editor_ids[0] . " ,\n\t\t\t" . $editor_ids[1] . " ,\n\t\t\t'" . $this->year . "',\n\t\t\t'" . $this->page_nbr . "',\n\t\t\t'" . $this->illustration . "',\n\t\t\t'" . $this->size . "',\n\t\t\t'" . $this->accompagnement . "',\n\t\t\t" . $collection_id . " ,\n\t\t\t" . $subcollection_id . " ,\n\t\t\t'" . $this->nbr_in_collection . "',\n\t\t\t'" . $this->mention_edition . "',\n\t\t\t'" . $this->general_note . "',\n\t\t\t'" . $this->content_note . "',\n\t\t\t'" . $this->abstract_note . "',\n\t\t\t'" . $this->internal_index . "',\n\t\t\t'" . $this->statut . "',\n\t\t\t'" . $this->commentaire_gestion . "',\n\t\t\t'" . $this->signature . "',\n\t\t\t'" . $this->thumbnail_url . "',\n\t\t\t'" . clean_tags($this->free_index) . "',\n\t\t\t'" . $this->bibliographic_level . "',\n\t\t\t'" . $this->hierarchic_level . "',\n\t\t\t'" . $this->link_url . "',\n\t\t\t'" . $this->link_format . "',\n\t\t\t'" . $this->orinot_id . "',\n\t\t\t'" . $this->prix . "',\n\t\t\tsysdate(),\n\t\t\t'" . $date_parution_z3950 . "',\n\t\t\t'" . $this->indexation_lang . "'\n\t\t )"; $sql_result_ins = pmb_mysql_query($sql_ins) or die("Couldn't insert into table notices : " . $sql_ins); $notice_retour = pmb_mysql_insert_id(); audit::insert_creation(AUDIT_NOTICE, $notice_retour); if ($gestion_acces_active == 1) { $ac = new acces(); //traitement des droits acces user_notice if ($gestion_acces_user_notice == 1) { $dom_1 = $ac->setDomain(1); $dom_1->storeUserRights(0, $notice_retour); } //traitement des droits acces empr_notice if ($gestion_acces_empr_notice == 1) { $dom_2 = $ac->setDomain(2); $dom_2->storeUserRights(0, $notice_retour); } } // purge de la base des responsabilités de la notice intégrée... if ($notice_retour) { $rqt_del = "delete from responsability where responsability_notice='{$notice_retour}'"; $sql_result_del = pmb_mysql_query($rqt_del) or die("Couldn't purge table responsability : " . $rqt_del); } $rqt_ins = "insert into responsability (responsability_author, responsability_notice, responsability_fonction, responsability_type, responsability_ordre ) VALUES "; for ($i = 0; $i < sizeof($this->aut_array); $i++) { $aut['id'] = clean_string($this->aut_array[$i]['id']); $aut['name'] = clean_string($this->aut_array[$i]['entree']); $aut['rejete'] = clean_string($this->aut_array[$i]['rejete']); $aut['date'] = clean_string($this->aut_array[$i]['date']); $aut['type'] = $this->aut_array[$i]['type_auteur']; $aut['subdivision'] = clean_string($this->aut_array[$i]['subdivision']); $aut['numero'] = clean_string($this->aut_array[$i]['numero']); $aut['lieu'] = clean_string($this->aut_array[$i]['lieu']); $aut['ville'] = clean_string($this->aut_array[$i]['ville']); $aut['pays'] = clean_string($this->aut_array[$i]['pays']); $aut['web'] = clean_string($this->aut_array[$i]['web']); $aut['author_comment'] = clean_string($this->aut_array[$i]['author_comment']); $aut['authority_number'] = clean_string($this->aut_array[$i]['authority_number']); /* Origine de l'autorité : on reprend les infos d'origine de la notice pour les attribuées aux origines des autorités */ $id_origine_auth = 0; $id_origine_auth = origin_authorities::import($this->origine_notice); if ($id_origine_auth == 0) { $id_origine_auth = 1; } // import de l'autorité auteur si elle existe et conservation des infos sur l'origine de l'autorité if ($aut['authority_number'] != '' && $id_origine_auth) { $this->aut_array[$i]["id"] = $this->insert_authority_infos($aut['authority_number'], "author", $id_origine_auth, $aut); } if (!$this->aut_array[$i]["id"]) { $this->aut_array[$i]["id"] = auteur::import($aut); } if ($this->aut_array[$i]["id"]) { $rqt = $rqt_ins . " (" . $this->aut_array[$i]["id"] . "," . $notice_retour . ",'" . $this->aut_array[$i]['fonction'] . "'," . $this->aut_array[$i]['responsabilite'] . "," . $i . ") "; $res_ins = pmb_mysql_query($rqt, $dbh); } } // traitement des titres uniformes global $pmb_use_uniform_title; if ($pmb_use_uniform_title) { if (count($this->titres_uniformes)) { $ntu = new tu_notice($notice_retour); $ntu->update($this->titres_uniformes); } } // traitement des langues // langues de la publication $rqt_del = "delete from notices_langues where num_notice='{$notice_retour}' "; $res_del = pmb_mysql_query($rqt_del, $dbh); if (is_array($this->language_code) && count($this->language_code)) { $rqt_ins = "insert into notices_langues (num_notice, type_langue, code_langue, ordre_langue) VALUES "; foreach ($this->language_code as $ordre_lang => $code_lang) { if ($code_lang) { $rqt = $rqt_ins . " ('{$notice_retour}',0, '{$code_lang}', {$ordre_lang}) "; $res_ins = @pmb_mysql_query($rqt, $dbh); } } } // langues originales if (is_array($this->original_language_code) && count($this->original_language_code)) { $rqt_ins = "insert into notices_langues (num_notice, type_langue, code_langue, ordre_langue) VALUES "; foreach ($this->original_language_code as $ordre_lang => $code_lang) { if ($code_lang) { $rqt = $rqt_ins . " ('{$notice_retour}',1, '{$code_lang}', {$ordre_lang}) "; $res_ins = @pmb_mysql_query($rqt, $dbh); } } } // traitement des categories if ($this->categorisation_type == "categorisation_auto") { traite_categories_enreg($notice_retour, $this->categories); } else { $rqt_del = "delete from notices_categories where notcateg_notice='{$notice_retour}' "; $res_del = @pmb_mysql_query($rqt_del, $dbh); $rqt_ins = "insert into notices_categories (notcateg_notice, num_noeud, ordre_categorie) VALUES "; $rqt_ins_values = array(); foreach ($this->categories as $i => $category) { $id_categ = $category['categ_id']; if ($id_categ) { $rqt_ins_values[] = " ('{$notice_retour}','{$id_categ}', {$i}) "; } } $rqt_ins .= implode(",", $rqt_ins_values); $res_ins = @pmb_mysql_query($rqt_ins, $dbh); } //Traitement des champs personnalisés (du formulaire !!!) $p_perso = new parametres_perso("notices"); $nberrors = $p_perso->check_submited_fields(); $p_perso->rec_fields_perso($notice_retour); //Traitement import perso global $notice_id, $notice_org, $notice_type_org; if (function_exists('z_recup_noticeunimarc_suite') && function_exists('z_import_new_notice_suite')) { $notice_id = $notice_retour; if (!$notice_org) { $notice_tmp = $this->notice; } z_recup_noticeunimarc_suite($notice_tmp ? $notice_tmp : $notice_org); z_import_new_notice_suite(); $notice_tmp = ""; } //Recherche du titre uniforme automatique //global $opac_enrichment_bnf_sparql; //$opac_enrichment_bnf_sparql=1; $titre_uniforme = notice::getAutomaticTu($notice_retour); //Traitement upload vignette if (trim($this->flag_upload_vignette)) { $req = "select repertoire_path from upload_repertoire where repertoire_id ='" . $pmb_notice_img_folder_id . "'"; $res = pmb_mysql_query($req, $dbh); if (pmb_mysql_num_rows($res)) { $rep = pmb_mysql_fetch_object($res); } //le fichier if (file_exists($rep->repertoire_path . $this->flag_upload_vignette)) { rename($rep->repertoire_path . $this->flag_upload_vignette, $rep->repertoire_path . "img_" . $notice_retour); } //le champ $rqt_upd = "UPDATE notices SET thumbnail_url='" . addslashes($opac_url_base . "getimage.php?noticecode=&vigurl=¬ice_id=" . $notice_retour) . "' WHERE notice_id=" . $notice_retour; $res_ins = @pmb_mysql_query($rqt_upd, $dbh); } // Mise à jour des index de la notice notice::majNotices($notice_retour); // Mise à jour de la table notices_global_index notice::majNoticesGlobalIndex($notice_retour); // Mise à jour de la table notices_mots_global_index notice::majNoticesMotsGlobalIndex($notice_retour); //Calcul de la signature $sign = new notice_doublon(); $val = $sign->gen_signature($notice_retour); pmb_mysql_query("update notices set signature='{$val}' where notice_id=" . $notice_retour, $dbh); //synchro_rdf if ($pmb_synchro_rdf) { $synchro_rdf = new synchro_rdf(); } //Si on catalogue un article on recrée l'arborescence global $biblio_notice; //TODO AR //gérer le cas du bulletin (revient à intégrer le pério uniquement) if ($biblio_notice == 'art') { //Perios if (!$this->perio_id) { $new_perio = new serial(); $values = array(); $values['tit1'] = $this->perio_titre; $values['code'] = $this->perio_issn; $values['niveau_biblio'] = "s"; $values['niveau_hierar'] = "1"; $this->perio_id = $new_perio->update($values); //synchro_rdf if ($pmb_synchro_rdf) { $synchro_rdf->addRdf($this->perio_id, 0); } } //Bulletin if ($this->bull_id) { $req_art = "insert into analysis set analysis_bulletin='" . $this->bull_id . "',\n\t\t\t\t\tanalysis_notice='" . $notice_retour . "'"; pmb_mysql_query($req_art, $dbh); $req = "update bulletins set bulletin_notice='" . $this->perio_id . "' where bulletin_id='" . $this->bull_id . "'"; pmb_mysql_query($req, $dbh); } else { $new_bull = new bulletinage(0, $this->perio_id); $values = array(); $values['bul_no'] = $this->bull_num; $values['bul_date'] = $this->bull_mention; $values['date_date'] = $this->bull_date; $values['bul_titre'] = $this->bull_titre; $new_bull->update($values); $this->bull_id = $new_bull->bulletin_id; $req_art = "insert into analysis set analysis_bulletin='" . $this->bull_id . "',\n\t\t\t\t\tanalysis_notice='" . $notice_retour . "'"; pmb_mysql_query($req_art, $dbh); //synchro_rdf if ($pmb_synchro_rdf) { $synchro_rdf->addRdf(0, $this->bull_id); } } } else { if ($biblio_notice == "bull") { //Perios if (!$this->perio_id) { $new_perio = new serial(); $values = array(); $values['tit1'] = $this->perio_titre; $values['code'] = $this->perio_issn; $values['niveau_biblio'] = "s"; $values['niveau_hierar'] = "1"; $this->perio_id = $new_perio->update($values); //synchro_rdf if ($pmb_synchro_rdf) { $synchro_rdf->addRdf($this->perio_id, 0); } } if (!$this->bull_id) { $new_bull = new bulletinage(0, $this->perio_id); $values = array(); $values['bul_no'] = $this->bull_num; $values['bul_date'] = $this->bull_mention; $values['date_date'] = $this->bull_date; $values['bul_titre'] = $this->bull_titre; $new_bull->update($values); $this->bull_id = $new_bull->bulletin_id; //synchro_rdf if ($pmb_synchro_rdf) { $synchro_rdf->addRdf(0, $this->bull_id); } // $req = "update bulletins set bulletin_notice='".$this->perio_id."',num_notice='".$notice_retour."' where bulletin_id='".$this->bull_id."'"; // pmb_mysql_query($req,$dbh); //Faire un update en mettant l'id de la notice crée //file_put_contents('php://stderr', print_r($this->bull_id, true)); } if ($this->bull_notice) { $notice_bulletin = new notice(); $notice_bulletin->del_notice($notice_retour); $notice_retour = $this->bull_notice; } //Mise à jour de la table bulletins, ajout de la relation entre le bulletins et sa notice $req = "update bulletins set bulletin_notice='" . $this->perio_id . "',num_notice='" . $notice_retour . "' where bulletin_id='" . $this->bull_id . "'"; pmb_mysql_query($req, $dbh); //Insertion dans la table notices_relation, ajout de la relatioin entre la notice de bulletin et la notice de perio $req = "insert into notices_relations (num_notice, linked_notice, relation_type,rank) values('" . $notice_retour . "', '" . $this->perio_id . "', 'b','1')"; pmb_mysql_query($req, $dbh); } } //file_put_contents('php://stderr', print_r($notice_retour."\n", true)); //Exemplaires if (count($this->exemplaires)) { // global $section_995, $typdoc_995, $codstatdoc_995; // , $nb_expl_ignores; $section_995_ = new marc_list("section_995"); $section_995 = $section_995_->table; $typdoc_995_ = new marc_list("typdoc_995"); $typdoc_995 = $typdoc_995_->table; $codstatdoc_995_ = new marc_list("codstatdoc_995"); $codstatdoc_995 = $codstatdoc_995_->table; // $nb_expl_ignores=0; global $deflt_docs_statut, $deflt_docs_location, $deflt_lenders; foreach ($this->exemplaires as $info_expl) { /* RAZ expl */ $expl = array(); if ($notice_retour) { /* préparation du tableau à passer à la méthode */ $expl['cb'] = $info_expl['f']; //TODO AR // les raccrocher au bulletin et non sa notice // dans un second temps if ($this->bibliographic_level == "s" && $this->hierarchic_level == "2") { if ($this->bull_id) { $expl['notice'] = 0; $expl['bulletin'] = $this->bull_id; } else { if (!$this->bull_id && $notice_retour) { $expl['notice'] = $notice_retour; $expl['bulletin'] = 0; } } } else { $expl['notice'] = $notice_retour; $expl['bulletin'] = 0; } //$expl['bulletin'] = 0; // $expl['typdoc'] = $info_995['r']; à chercher dans docs_typdoc $data_doc = array(); //$data_doc['tdoc_libelle'] = $info_995['r']." -Type doc importé (".$book_lender_id.")"; $data_doc['tdoc_libelle'] = $typdoc_995[$info_expl['r']]; if (!$data_doc['tdoc_libelle']) { $data_doc['tdoc_libelle'] = "\$r non conforme -" . $info_expl['r'] . "-"; } $data_doc['duree_pret'] = 0; /* valeur par défaut */ $data_doc['tdoc_codage_import'] = $info_expl['r']; if ($tdoc_codage) { $data_doc['tdoc_owner'] = $deflt_lenders; } else { $data_doc['tdoc_owner'] = 0; } $expl['typdoc'] = docs_type::import($data_doc); $expl['cote'] = $info_expl['k']; // $expl['section'] = $info_995['q']; à chercher dans docs_section $data_doc = array(); $info_expl['q'] = trim($info_expl['q']); if (!$info_expl['q']) { $info_expl['q'] = "u"; } $data_doc['section_libelle'] = $section_995[$info_expl['q']]; $data_doc['sdoc_codage_import'] = $info_expl['q']; if ($sdoc_codage) { $data_doc['sdoc_owner'] = $deflt_lenders; } else { $data_doc['sdoc_owner'] = 0; } $expl['section'] = docs_section::import($data_doc); $expl['statut'] = $deflt_docs_statut; if ($info_expl['a']) { $expl['location'] = $info_expl['a']; } else { $expl['location'] = $deflt_docs_location; } // $expl['codestat'] = $info_995['q']; 'q' utilisé, éventuellement à fixer par combo_box $data_doc = array(); //$data_doc['codestat_libelle'] = $info_995['q']." -Pub visé importé (".$book_lender_id.")"; $data_doc['codestat_libelle'] = $codstatdoc_995[$info_expl['q']]; $data_doc['statisdoc_codage_import'] = $info_expl['q']; if ($statisdoc_codage) { $data_doc['statisdoc_owner'] = $deflt_lenders; } else { $data_doc['statisdoc_owner'] = 0; } $expl['codestat'] = docs_codestat::import($data_doc); $expl['note'] = $info_expl['u']; $expl['expl_owner'] = $deflt_lenders; if ($info_expl['m']) { $expl['date_depot'] = substr($info_expl['m'], 0, 4) . "-" . substr($info_expl['m'], 4, 2) . "-" . substr($info_expl['m'], 6, 2); } if ($info_expl['n']) { $expl['date_retour'] = substr($info_expl['n'], 0, 4) . "-" . substr($info_expl['n'], 4, 2) . "-" . substr($info_expl['n'], 6, 2); } exemplaire::import($expl); } } } //Documents numériques global $deflt_explnum_statut; foreach ($this->doc_nums as $doc_num) { if (!$doc_num['a']) { continue; } if (!$doc_num['s']) { $doc_num['s'] = $deflt_explnum_statut; } if ($doc_num['__nodownload__']) { if ($this->bibliographic_level == "b" && $this->hierarchic_level == "2") { explnum_add_url($notice_retour, $this->bull_id, $doc_num['b'], $doc_num['a'], $doc_num['s']); } else { explnum_add_url($notice_retour, 0, $doc_num['b'], $doc_num['a'], $doc_num['s']); } } else { if ($this->bibliographic_level == "b" && $this->hierarchic_level == "2") { explnum_add_from_url($notice_retour, $this->bull_id, $doc_num['b'], $doc_num['a'], true, $this->source_id, $doc_num['f'], $doc_num['p'], $doc_num['s']); } else { explnum_add_from_url($notice_retour, 0, $doc_num['b'], $doc_num['a'], true, $this->source_id, $doc_num['f'], $doc_num['p'], $doc_num['s']); } } } //synchro_rdf if ($pmb_synchro_rdf) { $synchro_rdf->addRdf($notice_retour, 0); } $retour = array($new_notice, $notice_retour); return $retour; }
function import($data) { global $msg; // cette méthode prend en entrée un tableau constitué des informations exemplaires suivantes : // $data['cb'] // $data['notice'] // $data['bulletin'] // $data['typdoc'] // $data['cote'] // $data['section'] // $data['statut'] // $data['location'] // $data['codestat'] // $data['creation'] // $data['modif'] // $data['note'] // $data['prix'] // $data['expl_owner'] // $data['cote_mandatory'] cote obligatoire = 1, non obligatoire = 0 // $data['quoi_faire'] que faire de cet exemplaire : // 0 : supprimer, 1 ou vide : Mettre à jour ou ajouter, 2 : ajouter si possible, sinon rien. global $dbh; // check sur le type de la variable passée en paramètre if (!sizeof($data) || !is_array($data)) { // si ce n'est pas un tableau ou un tableau vide, on retourne 0 $sql_log = pmb_mysql_query("insert into error_log (error_origin, error_text) values ('expl_" . addslashes(SESSid) . ".class', '" . $msg[544] . "') "); return 0; } if ($data['quoi_faire'] == "") { $data['quoi_faire'] = "2"; } if ((string) $data['quoi_faire'] == "0") { $sql_del = "delete from exemplaires where expl_cb='" . addslashes($data['cb']) . "' "; pmb_mysql_query($sql_del); return -1; } // check sur les éléments du tableau (cb, cote, notice, typdoc, section, statut, location, codestat, owner sont requis). $long_maxi = pmb_mysql_field_len(pmb_mysql_query("SELECT expl_cb FROM exemplaires limit 1"), 0); $data['cb'] = rtrim(substr(trim($data['cb']), 0, $long_maxi)); $long_maxi = pmb_mysql_field_len(pmb_mysql_query("SELECT expl_cote FROM exemplaires limit 1"), 0); $data['cote'] = rtrim(substr(trim($data['cote']), 0, $long_maxi)); $long_maxi = pmb_mysql_field_len(pmb_mysql_query("SELECT expl_prix FROM exemplaires limit 1"), 0); $data['prix'] = rtrim(substr(trim($data['prix']), 0, $long_maxi)); if ($data['expl_owner'] == "") { $sql_log = pmb_mysql_query("insert into error_log (error_origin, error_text) values ('expl_" . addslashes(SESSid) . ".class', 'No lender given') "); return 0; } if ($data['cb'] == "") { $sql_log = pmb_mysql_query("insert into error_log (error_origin, error_text) values ('expl_" . addslashes(SESSid) . ".class', '" . $msg[545] . "') "); return 0; } if ($data['cote'] == "") { if ($data['cote_mandatory'] == 1) { $sql_log = pmb_mysql_query("insert into error_log (error_origin, error_text) values ('expl_" . addslashes(SESSid) . ".class', '" . $msg[546] . "') "); return 0; } else { $sql_log = pmb_mysql_query("insert into error_log (error_origin, error_text) values ('expl_" . addslashes(SESSid) . ".class', '" . $msg[567] . "') "); } } if ($data['notice'] == 0) { if ($data['bulletin'] == 0) { $sql_log = pmb_mysql_query("insert into error_log (error_origin, error_text) values ('expl_" . addslashes(SESSid) . ".class', '" . $msg[547] . "') "); return 0; } } if ($data['typdoc'] == 0) { $sql_log = pmb_mysql_query("insert into error_log (error_origin, error_text) values ('expl_" . addslashes(SESSid) . ".class', '" . $msg[548] . "') "); return 0; } if ($data['section'] == 0) { $sql_log = pmb_mysql_query("insert into error_log (error_origin, error_text) values ('expl_" . addslashes(SESSid) . ".class', '" . $msg[549] . "') "); return 0; } if ($data['statut'] == 0) { $sql_log = pmb_mysql_query("insert into error_log (error_origin, error_text) values ('expl_" . addslashes(SESSid) . ".class', '" . $msg[550] . "') "); return 0; } if ($data['location'] == 0) { $sql_log = pmb_mysql_query("insert into error_log (error_origin, error_text) values ('expl_" . addslashes(SESSid) . ".class', '" . $msg[551] . "') "); return 0; } if ($data['codestat'] == 0) { $sql_log = pmb_mysql_query("insert into error_log (error_origin, error_text) values ('expl_" . addslashes(SESSid) . ".class', '" . $msg[552] . "') "); return 0; } if ($data['type_antivol'] == "") { $data['type_antivol'] = "1"; } // préparation de la requête $key0 = addslashes($data['cb']); $key1 = addslashes($data['cote']); /* vérification que l'exemplaire existe ou pas */ $exe = new stdClass(); $query = "SELECT expl_id FROM exemplaires WHERE expl_cb='{$key0}' LIMIT 1 "; $result = @pmb_mysql_query($query, $dbh); if (!$result) { die("can't SELECT exemplaires " . $query); } if (pmb_mysql_num_rows($result)) { $exe = pmb_mysql_fetch_object($result); } if (!$data['date_depot']) { $data['date_depot'] = "sysdate()"; } else { $data['date_depot'] = "'" . $data['date_depot'] . "'"; } if (!$data['date_retour']) { $data['date_retour'] = "sysdate()"; } else { $data['date_retour'] = "'" . $data['date_retour'] . "'"; } // l'exemplaire existe et on ne pouvait que l'ajouter, on retourne l'ID if ($exe->expl_id != "" && $data['quoi_faire'] == "2") { $sql_log = pmb_mysql_query("insert into error_log (error_origin, error_text) values ('expl_" . addslashes(SESSid) . ".class', '" . $msg[553] . $data['cb'] . "') "); return $exe->expl_id; } // l'exemplaire existe et on doit le mettre à jour if ($exe->expl_id != "" && $data['quoi_faire'] == "1") { $sql_a_faire = "update exemplaires SET "; $sql_a_faire_suite = " where expl_cb='" . addslashes($data['cb']) . "' "; } // l'exemplaire n'existe pas : on doit le créer if ($exe->expl_id == "") { $sql_a_faire = "insert into exemplaires SET "; $sql_a_faire_suite = ""; } $query = $sql_a_faire; $query .= "expl_cb='" . $key0 . "', "; $query .= "expl_notice='" . $data['notice'] . "', "; $query .= "expl_bulletin='" . $data['bulletin'] . "', "; $query .= "expl_typdoc='" . $data['typdoc'] . "', "; $query .= "expl_cote=trim('" . $key1 . "'), "; $query .= "expl_section='" . $data['section'] . "', "; $query .= "expl_statut='" . $data['statut'] . "', "; $query .= "expl_location='" . $data['location'] . "', "; $query .= "expl_codestat='" . $data['codestat'] . "', "; $query .= "expl_note='" . addslashes($data['note']) . "', "; $query .= "expl_comment='" . addslashes($data['comment']) . "', "; $query .= "expl_prix='" . addslashes($data['prix']) . "', "; $query .= "expl_owner='" . $data['expl_owner'] . "', "; $query .= "expl_date_depot=" . $data['date_depot'] . ", "; $query .= "expl_date_retour=" . $data['date_retour'] . ", "; $query .= "transfert_location_origine = " . $data['location'] . ", "; $query .= "transfert_statut_origine=" . $data['statut'] . ", "; $query .= "transfert_section_origine=" . $data['section'] . ", "; //$query .= "type_antivol=".$data['type_antivol'].", "; if ($data['creation']) { $query .= "create_date='" . $data['creation'] . "'"; } else { $query .= "create_date=sysdate() "; } $query .= $sql_a_faire_suite; $result = @pmb_mysql_query($query, $dbh); if (!$result) { die("can't INSERT into exemplaires " . $query); } if ($exe->expl_id = "") { audit::insert_creation(AUDIT_EXPL, pmb_mysql_insert_id($dbh)); return pmb_mysql_insert_id($dbh); } else { $sql_id = pmb_mysql_query("select expl_id from exemplaires where expl_cb='" . addslashes($data['cb']) . "' "); $exe = pmb_mysql_fetch_object($sql_id); audit::insert_modif(AUDIT_EXPL, $exe->expl_id); return $exe->expl_id; } }
static function check_if_exists($data) { global $dbh; $long_maxi = pmb_mysql_field_len(pmb_mysql_query("SELECT ed_name FROM publishers limit 1"), 0); $key = addslashes(rtrim(substr(preg_replace('/\\[|\\]/', '', rtrim(ltrim($data['name']))), 0, $long_maxi))); $ville = addslashes(trim($data['ville'])); $adr = addslashes(trim($data['adr'])); $ed_comment = addslashes(trim($data['ed_comment'])); $query = "SELECT ed_id FROM publishers WHERE ed_name='{$key}' and ed_ville = '{$ville}' "; $result = @pmb_mysql_query($query, $dbh); if (!$result) { die("can't SELECT publisher " . $query); } // resultat // recuperation du resultat de la recherche $tediteur = pmb_mysql_fetch_object($result); // et recuperation eventuelle de l'id if ($tediteur->ed_id) { return $tediteur->ed_id; } return 0; }
static function check_if_exists($data) { global $dbh; if (!sizeof($data) || !is_array($data)) { // si ce n'est pas un tableau ou un tableau vide, on retourne 0 return 0; } // check sur les éléments du tableau (data['name'] ou data['rejete'] est requis). $long_maxi_name = pmb_mysql_field_len(pmb_mysql_query("SELECT author_name FROM authors limit 1"), 0); $long_maxi_rejete = pmb_mysql_field_len(pmb_mysql_query("SELECT author_rejete FROM authors limit 1"), 0); $data['name'] = rtrim(substr(preg_replace('/\\[|\\]/', '', rtrim(ltrim($data['name']))), 0, $long_maxi_name)); $data['rejete'] = rtrim(substr(preg_replace('/\\[|\\]/', '', rtrim(ltrim($data['rejete']))), 0, $long_maxi_rejete)); if (!$data['name'] && !$data['rejete']) { return 0; } // check sur le type d'autorité if (!$data['type'] == 70 && !$data['type'] == 71 && !$data['type'] == 72) { return 0; } // tentative de récupérer l'id associée dans la base (implique que l'autorité existe) // préparation de la requête $key0 = $data['type']; $key1 = addslashes($data['name']); $key2 = addslashes($data['rejete']); $key3 = addslashes($data['date']); $key4 = addslashes($data['subdivision']); $key5 = addslashes($data['lieu']); $key6 = addslashes($data['ville']); $key7 = addslashes($data['pays']); $key8 = addslashes($data['numero']); $data['lieu'] = addslashes($data['lieu']); $data['ville'] = addslashes($data['ville']); $data['pays'] = addslashes($data['pays']); $data['subdivision'] = addslashes($data['subdivision']); $data['numero'] = addslashes($data['numero']); $data['author_comment'] = addslashes($data['author_comment']); $data['web'] = addslashes($data['web']); $query = "SELECT author_id FROM authors WHERE author_type='{$key0}' AND author_name='{$key1}' AND author_rejete='{$key2}' AND author_date='{$key3}'"; if ($data["type"] > 70) { $query .= " and author_subdivision='{$key4}' and author_lieu='{$key5}' and author_ville='{$key6}' and author_pays='{$key7}' and author_numero='{$key8}'"; } $query .= " LIMIT 1"; $result = pmb_mysql_query($query, $dbh); if (!$result) { die("can't SELECT in database"); } // résultat // récupération du résultat de la recherche $aut = pmb_mysql_fetch_object($result); // du résultat et récupération éventuelle de l'id if ($aut->author_id) { return $aut->author_id; } else { return 0; } }
function import($data) { // cette méthode prend en entrée un tableau constitué des informations suivantes : // $data['lender_libelle'] global $dbh; // check sur le type de la variable passée en paramètre if (!sizeof($data) || !is_array($data)) { // si ce n'est pas un tableau ou un tableau vide, on retourne 0 return 0; } // check sur les éléments du tableau $long_maxi = pmb_mysql_field_len(pmb_mysql_query("SELECT lender_libelle FROM lenders limit 1"), 0); $data['lender_libelle'] = rtrim(substr(preg_replace('/\\[|\\]/', '', rtrim(ltrim($data['lender_libelle']))), 0, $long_maxi)); if ($data['lender_libelle'] == "") { return 0; } // préparation de la requête $key0 = addslashes($data['lender_libelle']); /* vérification que le lender existe */ $query = "SELECT idlender FROM lenders WHERE lender_libelle='{$key0}' LIMIT 1 "; $result = @pmb_mysql_query($query, $dbh); if (!$result) { die("can't SELECT lenders " . $query); } $lenders = pmb_mysql_fetch_object($result); /* le lender existe, on retourne l'ID */ if ($lenders->idlender) { return $lenders->idlender; } // id non-récupérée, il faut créer la forme. $query = "INSERT INTO lenders SET lender_libelle='" . $key0 . "' "; $result = @pmb_mysql_query($query, $dbh); if (!$result) { die("can't INSERT into lenders " . $query); } return pmb_mysql_insert_id($dbh); }
function getData() { global $dbh; global $msg; if ($this->id_expl == 0 && $this->cb_expl == "") { // aucun identifiant. on retourne un tableau vide $this->id_empr = 0; $this->id_expl = 0; $this->pret_date = ""; $this->pret_retour = ""; $this->cb_expl = ""; $this->type_doc = ""; $this->statut_doc = ""; $this->titre_auteur = ""; $this->owner = ""; $this->date_pret_display = ""; $this->date_retour_display = ""; $this->etat = 0; $this->display = $msg[4052]; } else { $sql_dates = " date_format(pret_date, '" . $msg["format_date"] . "') as aff_pret_date, "; $sql_dates .= " date_format(pret_retour, '" . $msg["format_date"] . "') as aff_pret_retour, "; $sql_dates .= " IF(pret_retour>sysdate(),0,1) as retard "; if ($this->id_expl != 0) { $requete = "SELECT pret_idempr, pret_idexpl, pret_date, pret_retour, expl_cb, expl_typdoc, expl_statut, tit1, expl_owner, {$sql_dates} FROM pret, exemplaires, notices WHERE pret_idexpl='" . $this->id_expl . "' and pret_idexpl=expl_id and expl_notice=notice_id LIMIT 1 "; } else { $requete = "SELECT pret_idempr, pret_idexpl, pret_date, pret_retour, expl_cb, expl_typdoc, tit1, expl_owner, {$sql_dates} FROM pret, exemplaires, notices, authors WHERE expl_cb='" . $this->cb_expl . "' and pret_idexpl=expl_id and expl_notice=notice_id LIMIT 1 "; } $result = @pmb_mysql_query($requete, $dbh); if (pmb_mysql_num_rows($result)) { $temp = pmb_mysql_fetch_object($result); pmb_mysql_free_result($result); $this->id_empr = $temp->pret_idempr; $this->id_expl = $temp->pret_idexpl; $this->pret_date = $temp->pret_date; $this->pret_retour = $temp->pret_retour; $this->cb_expl = $temp->expl_cb; $requete = "select tdoc_libelle from docs_type where idtyp_doc='" . $temp->expl_typdoc . "' "; $result = @pmb_mysql_query($requete, $dbh); $typdoc = pmb_mysql_fetch_object($result); pmb_mysql_free_result($result); $this->type_doc = $typdoc->tdoc_libelle; $requete = "select statut_libelle from docs_statut where idstatut='" . $temp->expl_statut . "' "; $result = @pmb_mysql_query($requete, $dbh); $statdoc = pmb_mysql_fetch_object($result); pmb_mysql_free_result($result); $this->statut_doc = $statdoc->statut_libelle; $this->titre_auteur = $temp->tit1; $requete = "select lender_libelle from lenders where idlender='" . $temp->expl_owner . "' "; $result = @pmb_mysql_query($requete, $dbh); $lender = pmb_mysql_fetch_object($result); pmb_mysql_free_result($result); $this->owner = $lender->lender_libelle; $this->date_pret_display = $temp->aff_pret_date; $this->date_retour_display = $temp->aff_pret_retour; $this->etat = 1; $this->display = "Prêt existant"; } else { // pas de prêt avec cette clé : on va aller chercher le expl_cb avec l'id ou l'inverse $long_maxi_cb_expl = pmb_mysql_field_len(pmb_mysql_query("SELECT expl_cb FROM exemplaires limit 1"), 0); $this->cb_expl = rtrim(substr(pmb_preg_replace('/\\[|\\]/', '', rtrim(ltrim($this->cb_expl))), 0, $long_maxi_cb_expl)); if ($this->id_expl == 0) { /* ici la recherche de l'id_expl */ $query = "SELECT expl_id, expl_cb FROM exemplaires WHERE expl_cb='{$key_cb_expl}' LIMIT 1 "; } else { /* ici la recherche du cb à partir de l'id */ $query = "SELECT expl_id, expl_cb FROM exemplaires WHERE expl_id='" . $this->id_expl . "' LIMIT 1 "; } $result = @pmb_mysql_query($query, $dbh) or die("can't SELECT exemplaires " . $query); if (pmb_mysql_num_rows($result) == 0) { /* on n'a trouvé aucun exemplaire */ $this->id_empr = 0; $this->id_expl = 0; $this->pret_date = ""; $this->pret_retour = ""; $this->cb_expl = ""; $this->type_doc = ""; $this->statut_doc = ""; $this->titre_auteur = ""; $this->owner = ""; $this->date_pret_display = ""; $this->date_retour_display = ""; $this->etat = 3; $this->display = "Exemplaire introuvable"; } else { $expl = pmb_mysql_fetch_object($result); $this->id_expl = $expl->expl_id; $this->cb_expl = $expl->expl_cb; $this->pret_retour = ""; $this->type_doc = ""; $this->statut_doc = ""; $this->titre_auteur = ""; $this->owner = ""; $this->date_pret_display = ""; $this->date_retour_display = ""; $this->etat = 2; $this->display = "Prêt possible, inexistant avec cette clé"; } } } }
function desc_table($dbh, $table) { $querry = "Select * from {$table}"; $res = pmb_mysql_query($querry, $dbh); $nbr = pmb_mysql_num_fields($res); if ($nbr) { for ($j = 0; $j < $nbr; $j++) { $desc_table[$j][0] = pmb_mysql_field_name($res, $j); $desc_table[$j][1] = pmb_mysql_field_type($res, $j); $desc_table[$j][2] = pmb_mysql_field_len($res, $j); $desc_table[$j][3] = estNumerique($desc_table[$j][1], $desc_table[$j][2]); // j'ai seulement besoin de l'auto_increment, $desc_table[$j][4] est vrai si trouv?! $desc_table[$j][4] = array_search("auto_increment", explode(" ", pmb_mysql_field_flags($res, $j))); } //print_r($desc_table); return $desc_table; } }
function fetch_data() { global $dbh; //enumerate tables $res = pmb_mysql_list_tables(DATA_BASE); $i = 0; while ($i < pmb_mysql_num_rows($res)) { $update_a_faire = 0; /* permet de gérer les id auto_increment qui auraient pour valeur 0 */ $table_name = pmb_mysql_tablename($res, $i); bzwrite($this->fptr, "delete from {$table_name};\n"); $this->dump .= "delete from {$table_name};\n"; //parse the field info first $res2 = pmb_mysql_query("select * from {$table_name} order by 1 ", $dbh); $nf = pmb_mysql_num_fields($res2); $nr = pmb_mysql_num_rows($res2); $fields = ''; $values = ''; for ($b = 0; $b < $nf; $b++) { $fn = pmb_mysql_field_name($res2, $b); $ft = pmb_mysql_field_type($res2, $b); $fs = pmb_mysql_field_len($res2, $b); $ff = pmb_mysql_field_flags($res2, $b); $is_numeric = false; switch (strtolower($ft)) { case "int": $is_numeric = true; break; case "blob": $is_numeric = false; break; case "real": $is_numeric = true; break; case "string": $is_numeric = false; break; case "unknown": switch (intval($fs)) { case 4: // little weakness here... // there is no way (thru the PHP/MySQL interface) // to tell the difference between a tinyint and a year field type $is_numeric = true; break; default: $is_numeric = true; break; } break; case "timestamp": $is_numeric = true; break; case "date": $is_numeric = false; break; case "datetime": $is_numeric = false; break; case "time": $is_numeric = false; break; default: //future support for field types that are not recognized //(hopefully this will work without need for future modification) $is_numeric = true; //I'm assuming new field types will follow SQL numeric syntax.. // this is where this support will breakdown break; } $fields ? $fields .= ', ' . $fn : ($fields .= $fn); $fna[$b] = $fn; $ina[$b] = $is_numeric; } //parse out the table's data and generate the SQL INSERT statements in order to replicate the data itself... for ($c = 0; $c < $nr; $c++) { $row = pmb_mysql_fetch_row($res2); $values = ''; for ($d = 0; $d < $nf; $d++) { $data = strval($row[$d]); if ($d == 0 && strval($row[$d]) == 0) { /* traiter ici l'insertion avec valeur 1 pour id autoincrement et update à suivre */ $values ? $values .= ', ' . '1' : ($values .= '1'); $cle_update = pmb_mysql_field_name($res2, 0); $update_a_faire = 1; } else { if ($ina[$d] == true) { $values ? $values .= ', ' . intval($data) : ($values .= intval($data)); } else { $values ? $values .= ", \"" . pmb_mysql_escape_string($data) . "\"" : ($values .= "\"" . pmb_mysql_escape_string($data) . "\""); } } } bzwrite($this->fptr, "insert into {$table_name} ({$fields}) values ({$values});\n"); $this->dump .= "insert into {$table_name} ({$fields}) values ({$values});\n"; if ($update_a_faire == 1) { $update_a_faire = 0; bzwrite($this->fptr, "update {$table_name} set " . $cle_update . "='0' where " . $cle_update . "='1';\n"); $this->dump .= "update {$table_name} set " . $cle_update . "='0' where " . $cle_update . "='1';\n"; } } pmb_mysql_free_result($res2); $i++; } }
function table_dump($table_name, $fp) { global $dbh; fwrite($fp, "#" . $table_name . "\r\n"); fwrite($fp, "drop table if exists " . $table_name . ";\r\n"); //Get strucutre fwrite($fp, create_statement($table_name) . "\n"); //enumerate tables $update_a_faire = 0; /* permet de gérer les id auto_increment qui auraient pour valeur 0 */ //parse the field info first $res2 = pmb_mysql_query("select * from {$table_name} order by 1 ", $dbh); if ($res2) { $nf = pmb_mysql_num_fields($res2); $nr = pmb_mysql_num_rows($res2); } $fields = ''; $values = ''; if ($nf) { for ($b = 0; $b < $nf; $b++) { $fn = pmb_mysql_field_name($res2, $b); $ft = pmb_mysql_field_type($res2, $b); $fs = pmb_mysql_field_len($res2, $b); $ff = pmb_mysql_field_flags($res2, $b); $is_numeric = false; switch (strtolower($ft)) { case "int": $is_numeric = true; break; case "blob": $is_numeric = false; break; case "real": $is_numeric = true; break; case "string": $is_numeric = false; break; case "unknown": switch (intval($fs)) { case 4: // little weakness here... // there is no way (thru the PHP/MySQL interface) // to tell the difference between a tinyint and a year field type $is_numeric = true; break; default: $is_numeric = true; break; } break; case "timestamp": // Afin de résoudre le pb des timestamp pas corrects en restauration $is_numeric=true; $is_numeric = false; break; case "date": $is_numeric = false; break; case "datetime": $is_numeric = false; break; case "time": $is_numeric = false; break; case "geometry": $is_numeric = false; break; default: //future support for field types that are not recognized //(hopefully this will work without need for future modification) $is_numeric = true; //I'm assuming new field types will follow SQL numeric syntax.. // this is where this support will breakdown break; } (string) $fields != "" ? $fields .= ', ' . $fn : ($fields .= $fn); $fna[$b] = $fn; $ina[$b] = $is_numeric; } } //parse out the table's data and generate the SQL INSERT statements in order to replicate the data itself... if ($nr) { for ($c = 0; $c < $nr; $c++) { $row = pmb_mysql_fetch_row($res2); $values = ''; for ($d = 0; $d < $nf; $d++) { $data = strval($row[$d]); if ($ina[$d] == true) { (string) $values != "" ? $values .= ', ' . floatval($data) : ($values .= floatval($data)); } else { (string) $values != "" ? $values .= ", \"" . pmb_mysql_real_escape_string($data) . "\"" : ($values .= "\"" . pmb_mysql_real_escape_string($data) . "\""); } } fwrite($fp, "insert into {$table_name} ({$fields}) values ({$values});\r\n"); if ($update_a_faire == 1) { $update_a_faire = 0; fwrite($fp, "update {$table_name} set " . $cle_update . "='0' where " . $cle_update . "='1';\r\n"); } } } if ($res2) { pmb_mysql_free_result($res2); } }
function import($data) { // cette méthode prend en entrée un tableau constitué des informations éditeurs suivantes : // $data['name'] Nom de la collection // $data['coll_parent'] id de l'éditeur parent de la collection // $data['issn'] numéro ISSN de la collection global $dbh; // check sur le type de la variable passée en paramètre if (!sizeof($data) || !is_array($data)) { // si ce n'est pas un tableau ou un tableau vide, on retourne 0 return 0; } // check sur les éléments du tableau (data['name'] est requis). $long_maxi_name = pmb_mysql_field_len(pmb_mysql_query("SELECT sub_coll_name FROM sub_collections limit 1"), 0); $data['name'] = rtrim(substr(preg_replace('/\\[|\\]/', '', rtrim(ltrim($data['name']))), 0, $long_maxi_name)); //si on a pas d'id, on peut avoir les infos de la collection if (!$data['coll_parent']) { if ($data['collection']) { //on les a, on crée l'éditeur $data['coll_parent'] = collection::import($data['collection']); } } if ($data['name'] == "" || $data['coll_parent'] == 0) { /* il nous faut impérativement une collection parente */ return 0; } // préparation de la requête $key0 = addslashes($data['name']); $key1 = $data['coll_parent']; $key2 = addslashes($data['issn']); /* vérification que la collection existe bien ! */ $query = "SELECT collection_id FROM collections WHERE collection_id='{$key1}' LIMIT 1 "; $result = @pmb_mysql_query($query, $dbh); if (!$result) { die("can't SELECT colections " . $query); } if (pmb_mysql_num_rows($result) == 0) { return 0; } /* vérification que la sous-collection existe */ $query = "SELECT sub_coll_id FROM sub_collections WHERE sub_coll_name='{$key0}' AND sub_coll_parent='{$key1}' LIMIT 1 "; $result = @pmb_mysql_query($query, $dbh); if (!$result) { die("can't SELECT sub_collections " . $query); } $subcollection = pmb_mysql_fetch_object($result); /* la sous-collection existe, on retourne l'ID */ if ($subcollection->sub_coll_id) { return $subcollection->sub_coll_id; } // id non-récupérée, il faut créer la forme. $query = "INSERT INTO sub_collections SET sub_coll_name='{$key0}', "; $query .= "sub_coll_parent='{$key1}', "; $query .= "sub_coll_issn='{$key2}', "; $query .= "subcollection_web='" . addslashes($data["subcollection_web"]) . "', "; $query .= "subcollection_comment='" . addslashes($data["comment"]) . "', "; $query .= "index_sub_coll=' " . strip_empty_words($key0) . " " . strip_empty_words($key2) . " ' "; $result = @pmb_mysql_query($query, $dbh); if (!$result) { die("can't INSERT into sub_collections" . $query); } $id = pmb_mysql_insert_id($dbh); audit::insert_creation(AUDIT_COLLECTION, $id); return $id; }