function traite_exemplaires()
{
    global $nb_expl_ignores, $bulletin_ex;
    global $prix, $notice_id, $info_996, $info_999, $typdoc_995, $tdoc_codage, $book_lender_id, $section_995, $sdoc_codage, $book_statut_id, $codstatdoc_995, $statisdoc_codage, $cote_mandatory, $book_location_id;
    global $suffix;
    // lu en 010$d de la notice
    $price = $prix[0];
    // la zone 995 est répétable
    for ($nb_expl = 0; $nb_expl < sizeof($info_996); $nb_expl++) {
        /* RAZ expl */
        $expl = array();
        $data = array();
        /*if(!$info_996[$nb_expl]['a'])$info_996[$nb_expl]['a'] ="Indéterminé";
        		$data['lender_libelle']=$info_996[$nb_expl]['a'];
        		$book_lender_id=lender::import($data);*/
        //Propriétaire
        if (trim($info_996[$nb_expl]['a'])) {
            $requete = "SELECT idlender FROM lenders WHERE lender_libelle LIKE '" . addslashes($info_996[$nb_expl]['a']) . "'";
            $res = mysql_query($requete);
            if (mysql_num_rows($res) && ($id = mysql_result($res, 0, 0))) {
                $local_book_lender_id = $id;
            } else {
                $local_book_lender_id = $book_lender_id;
            }
        } else {
            $local_book_lender_id = $book_lender_id;
        }
        /* préparation du tableau à passer à la méthode */
        $cbarre = $info_996[$nb_expl]['f'];
        if (!$cbarre) {
            $cbarre = "ind";
        }
        $pb = 1;
        $num_login = 1;
        $expl['cb'] = $cbarre;
        while ($pb == 1) {
            $q = "SELECT expl_cb FROM exemplaires WHERE expl_cb='" . addslashes($expl['cb']) . "' LIMIT 1 ";
            $r = mysql_query($q);
            $nb = mysql_num_rows($r);
            if ($nb) {
                $expl['cb'] = $cbarre . "-" . $num_login;
                $num_login++;
            } else {
                $pb = 0;
            }
        }
        if ($info_996[$nb_expl]['f'] != $expl['cb']) {
            $mon_msg = "ERREUR : l'exemplaire avec le code barres : " . $info_996[$nb_expl]['f'] . " existe déjà donc il ne sera pas créé";
            mysql_query("insert into error_log (error_origin, error_text) values ('import_" . addslashes(SESSid) . ".inc', '" . addslashes($mon_msg) . "') ");
            continue;
        }
        if ($bulletin_ex) {
            $expl['bulletin'] = $bulletin_ex;
            $expl['notice'] = 0;
        } else {
            $expl['notice'] = $notice_id;
            $expl['bulletin'] = 0;
        }
        $data_doc = array();
        $data_doc['tdoc_libelle'] = $info_996[$nb_expl]['e'];
        if (!$data_doc['tdoc_libelle']) {
            $data_doc['tdoc_libelle'] = "Indéterminé";
        }
        $requete = "SELECT idtyp_doc FROM docs_type WHERE tdoc_libelle LIKE '" . addslashes($data_doc['tdoc_libelle']) . "'";
        $res = mysql_query($requete);
        if (mysql_num_rows($res) && ($id = mysql_result($res, 0, 0))) {
            $expl['typdoc'] = $id;
        } else {
            $data_doc['duree_pret'] = 0;
            /* valeur par défaut */
            $data_doc['tdoc_codage_import'] = $data_doc['tdoc_libelle'];
            if ($tdoc_codage) {
                $data_doc['tdoc_owner'] = $local_book_lender_id;
            } else {
                $data_doc['tdoc_owner'] = 0;
            }
            $expl['typdoc'] = docs_type::import($data_doc);
        }
        $expl['cote'] = $info_996[$nb_expl]['k'];
        if (!$info_996[$nb_expl]['x']) {
            $info_996[$nb_expl]['x'] = "Indéterminé";
        }
        $requete = "SELECT idsection FROM docs_section WHERE section_libelle LIKE '" . addslashes($info_996[$nb_expl]['x']) . "'";
        $res = mysql_query($requete);
        if (mysql_num_rows($res) && ($id = mysql_result($res, 0, 0))) {
            $expl['section'] = $id;
        } else {
            $data_doc = array();
            $data_doc['section_libelle'] = $info_996[$nb_expl]['x'];
            $data_doc['sdoc_codage_import'] = $info_996[$nb_expl]['x'];
            if ($sdoc_codage) {
                $data_doc['sdoc_owner'] = $local_book_lender_id;
            } else {
                $data_doc['sdoc_owner'] = 0;
            }
            $expl['section'] = docs_section::import($data_doc);
        }
        if (!$info_996[$nb_expl]['1']) {
            $info_996[$nb_expl]['1'] = "Indéterminé";
        }
        $requete = "SELECT  idstatut FROM docs_statut WHERE statut_libelle LIKE '" . addslashes($info_996[$nb_expl]['1']) . "'";
        $res = mysql_query($requete);
        if (mysql_num_rows($res) && ($id = mysql_result($res, 0, 0))) {
            $expl['statut'] = $id;
        } else {
            $data_doc = array();
            $data_doc['statut_libelle'] = $info_996[$nb_expl]['1'];
            $data_doc['pret_flag'] = 1;
            $data_doc['statusdoc_codage_import'] = $info_996[$nb_expl]['1'];
            if ($sdoc_codage) {
                $data_doc['statusdoc_owner'] = $local_book_lender_id;
            } else {
                $data_doc['statusdoc_owner'] = 0;
            }
            $expl['statut'] = docs_statut::import($data_doc);
        }
        $requete = "SELECT idlocation FROM docs_location WHERE location_libelle LIKE '" . addslashes($info_996[$nb_expl]['v']) . "'";
        $res = mysql_query($requete);
        if (mysql_num_rows($res) && ($id = mysql_result($res, 0, 0))) {
            $expl['location'] = $id;
        } else {
            $expl['location'] = $book_location_id;
        }
        if (!$info_996[$nb_expl]['c']) {
            $info_996[$nb_expl]['c'] = "Indéterminé";
        }
        $requete = "SELECT idcode FROM docs_codestat WHERE codestat_libelle  LIKE '" . addslashes($info_996[$nb_expl]['c']) . "'";
        $res = mysql_query($requete);
        if (mysql_num_rows($res) && ($id = mysql_result($res, 0, 0))) {
            $expl['codestat'] = $id;
        } else {
            $data_doc = array();
            $data_doc['codestat_libelle'] = $info_996[$nb_expl]['c'];
            $data_doc['statisdoc_codage_import'] = $info_996[$nb_expl]['c'];
            if ($statisdoc_codage) {
                $data_doc['statisdoc_owner'] = $local_book_lender_id;
            } else {
                $data_doc['statisdoc_owner'] = 0;
            }
            $expl['codestat'] = docs_codestat::import($data_doc);
        }
        if ($info_996[$nb_expl]['4']) {
            $expl['creation'] = $info_996[$nb_expl]['4'];
        }
        $expl['note'] = $info_996[$nb_expl]['u'];
        $expl['comment'] = $info_996[$nb_expl]['z'];
        $expl['prix'] = $price;
        $expl['expl_owner'] = $local_book_lender_id;
        $expl['cote_mandatory'] = $cote_mandatory;
        $expl['date_depot'] = substr($info_996[$nb_expl]['m'], 0, 4) . "-" . substr($info_996[$nb_expl]['m'], 4, 2) . "-" . substr($info_996[$nb_expl]['m'], 6, 2);
        $expl['date_retour'] = substr($info_996[$nb_expl]['n'], 0, 4) . "-" . substr($info_996[$nb_expl]['n'], 4, 2) . "-" . substr($info_996[$nb_expl]['n'], 6, 2);
        // quoi_faire
        $expl['quoi_faire'] = 2;
        $expl_id = exemplaire::import($expl);
        if ($expl_id == 0) {
            $nb_expl_ignores++;
        } else {
            //Champ perso d'exemplaire
            //echo "Passe ici<br>";
            foreach ($info_999 as $key => $value) {
                if ($value["f"] == $info_996[$nb_expl]['f']) {
                    //Je suis bien sur un cp de cet exemplaire
                    if (!renseigne_cp($value["n"], $value["a"], $expl_id, "expl")) {
                        $mon_msg = "La valeur  : " . $value["a"] . " n'a pas été reprise dans le champ personalisé : " . $value["n"] . " car le champ n'existe pas";
                        mysql_query("insert into error_log (error_origin, error_text) values ('import_" . addslashes(SESSid) . ".inc', '" . addslashes($mon_msg) . "') ");
                    } else {
                        unset($info_999[$key]);
                    }
                }
            }
        }
    }
    // fin for
}
Exemplo n.º 2
0
function traite_exemplaires()
{
    global $nb_expl_ignores, $bulletin_ex;
    global $prix, $notice_id, $info_996_9, $info_999, $typdoc_995, $tdoc_codage, $book_lender_id, $section_995, $sdoc_codage, $book_statut_id, $codstatdoc_995, $statisdoc_codage, $cote_mandatory, $book_location_id;
    global $suffix;
    // lu en 010$d de la notice
    $price = $prix[0];
    $exemplaires = array();
    for ($i = 0; $i < count($info_996_9); $i++) {
        foreach ($info_996_9[$i] as $value) {
            if (preg_match("/^(.*?):(.*)\$/", $value, $matches)) {
                $exemplaires[$i][$matches[1]] = $matches[2];
            }
        }
    }
    // la zone 995 est répétable
    for ($nb_expl = 0; $nb_expl < sizeof($exemplaires); $nb_expl++) {
        /* RAZ expl */
        $expl = array();
        $data = array();
        /*if(!$info_996[$nb_expl]['a'])$info_996[$nb_expl]['a'] ="Indéterminé";
        		$data['lender_libelle']=$info_996[$nb_expl]['a'];
        		$book_lender_id=lender::import($data);*/
        //Propriétaire
        if ($tmp = trim($exemplaires[$nb_expl]["lender_libelle"])) {
            $requete = "SELECT idlender FROM lenders WHERE lender_libelle LIKE '" . addslashes($tmp) . "'";
            $res = mysql_query($requete);
            if (mysql_num_rows($res) && ($id = mysql_result($res, 0, 0))) {
                $local_book_lender_id = $id;
            } else {
                $local_book_lender_id = $book_lender_id;
            }
        } else {
            $local_book_lender_id = $book_lender_id;
        }
        /* préparation du tableau à passer à la méthode */
        $cbarre = $exemplaires[$nb_expl]["expl_cb"];
        if (!$cbarre) {
            $mon_msg = "ERREUR : J'ai un exemplaire sans code barres il ne sera donc pas créé";
            affiche_mes_erreurs($mon_msg);
            continue;
        }
        $pb = 1;
        $num_login = 1;
        $expl['cb'] = $cbarre;
        while ($pb == 1) {
            $q = "SELECT expl_cb FROM exemplaires WHERE expl_cb='" . addslashes($expl['cb']) . "' LIMIT 1 ";
            $r = mysql_query($q);
            $nb = mysql_num_rows($r);
            if ($nb) {
                $expl['cb'] = $cbarre . "-" . $num_login;
                $num_login++;
            } else {
                $pb = 0;
            }
        }
        if ($cbarre != $expl['cb']) {
            $mon_msg = "ERREUR : l'exemplaire avec le code barres : " . $cbarre . " existe déjà donc il ne sera pas créé";
            affiche_mes_erreurs($mon_msg);
            continue;
        }
        if ($bulletin_ex) {
            $expl['bulletin'] = $bulletin_ex;
            $expl['notice'] = 0;
        } else {
            $expl['notice'] = $notice_id;
            $expl['bulletin'] = 0;
        }
        //Support exemplaire
        $data_doc = array();
        $data_doc['tdoc_libelle'] = $exemplaires[$nb_expl]["tdoc_libelle"];
        //if (!$data_doc['tdoc_libelle']) $data_doc['tdoc_libelle'] = "Indéterminé" ;
        $requete = "SELECT idtyp_doc FROM docs_type WHERE tdoc_libelle LIKE '" . addslashes($data_doc['tdoc_libelle']) . "'";
        $res = mysql_query($requete);
        if ($data_doc['tdoc_libelle'] && mysql_num_rows($res) && ($id = mysql_result($res, 0, 0))) {
            $expl['typdoc'] = $id;
        } else {
            $data_doc['duree_pret'] = 0;
            /* valeur par défaut */
            $data_doc['tdoc_codage_import'] = $exemplaires[$nb_expl]["tdoc_codage_import"];
            if ($tdoc_codage) {
                $data_doc['tdoc_owner'] = $local_book_lender_id;
            } else {
                $data_doc['tdoc_owner'] = 0;
            }
            $expl['typdoc'] = docs_type::import($data_doc);
        }
        $expl['cote'] = $exemplaires[$nb_expl]["expl_cote"];
        //Section
        $data_doc = array();
        $data_doc['section_libelle'] = $exemplaires[$nb_expl]["section_libelle"];
        $requete = "SELECT idsection FROM docs_section WHERE section_libelle LIKE '" . addslashes($data_doc['section_libelle']) . "'";
        $res = mysql_query($requete);
        if ($data_doc['section_libelle'] && mysql_num_rows($res) && ($id = mysql_result($res, 0, 0))) {
            $expl['section'] = $id;
        } else {
            $data_doc['sdoc_codage_import'] = $exemplaires[$nb_expl]["sdoc_codage_import"];
            if ($sdoc_codage) {
                $data_doc['sdoc_owner'] = $local_book_lender_id;
            } else {
                $data_doc['sdoc_owner'] = 0;
            }
            $expl['section'] = docs_section::import($data_doc);
        }
        //Statut
        $data_doc = array();
        $data_doc['statut_libelle'] = $exemplaires[$nb_expl]["statut_libelle"];
        $requete = "SELECT  idstatut FROM docs_statut WHERE statut_libelle LIKE '" . addslashes($data_doc['statut_libelle']) . "'";
        $res = mysql_query($requete);
        if ($data_doc['statut_libelle'] && mysql_num_rows($res) && ($id = mysql_result($res, 0, 0))) {
            $expl['statut'] = $id;
        } elseif ($exemplaires[$nb_expl]["statusdoc_codage_import"]) {
            $data_doc['pret_flag'] = 1;
            $data_doc['statusdoc_codage_import'] = $exemplaires[$nb_expl]["statusdoc_codage_import"];
            if ($sdoc_codage) {
                $data_doc['statusdoc_owner'] = $local_book_lender_id;
            } else {
                $data_doc['statusdoc_owner'] = 0;
            }
            $expl['statut'] = docs_statut::import($data_doc);
        } else {
            $expl['statut'] = $book_statut_id;
        }
        //Localisation
        $requete = "SELECT idlocation FROM docs_location WHERE location_libelle LIKE '" . addslashes($exemplaires[$nb_expl]["location_libelle"]) . "'";
        $res = mysql_query($requete);
        if (mysql_num_rows($res) && ($id = mysql_result($res, 0, 0))) {
            $expl['location'] = $id;
        } else {
            $expl['location'] = $book_location_id;
        }
        //Code stat
        $data_doc = array();
        $data_doc['codestat_libelle'] = $exemplaires[$nb_expl]["codestat_libelle"];
        $requete = "SELECT idcode FROM docs_codestat WHERE codestat_libelle  LIKE '" . addslashes($data_doc['codestat_libelle']) . "'";
        $res = mysql_query($requete);
        if ($data_doc['codestat_libelle'] && mysql_num_rows($res) && ($id = mysql_result($res, 0, 0))) {
            $expl['codestat'] = $id;
        } else {
            $data_doc['statisdoc_codage_import'] = $exemplaires[$nb_expl]["statisdoc_codage_import"];
            if ($statisdoc_codage) {
                $data_doc['statisdoc_owner'] = $local_book_lender_id;
            } else {
                $data_doc['statisdoc_owner'] = 0;
            }
            $expl['codestat'] = docs_codestat::import($data_doc);
        }
        $expl['creation'] = $exemplaires[$nb_expl]["create_date"];
        $expl['note'] = $exemplaires[$nb_expl]["expl_note"];
        $expl['comment'] = $exemplaires[$nb_expl]["expl_comment"];
        $expl['prix'] = $exemplaires[$nb_expl]["expl_prix"];
        $expl['expl_owner'] = $local_book_lender_id;
        $expl['cote_mandatory'] = $cote_mandatory;
        $expl['date_depot'] = $exemplaires[$nb_expl]["date_depot"];
        $expl['date_retour'] = $exemplaires[$nb_expl]["date_retour"];
        // quoi_faire
        $expl['quoi_faire'] = 2;
        $expl_id = exemplaire::import($expl);
        if ($expl_id == 0) {
            $nb_expl_ignores++;
        } else {
            //Champ perso d'exemplaire
            //echo "Passe ici<br>";
            foreach ($info_999 as $key => $value) {
                if ($value["f"] == $cbarre) {
                    //Je suis bien sur un cp de cet exemplaire
                    if (!renseigne_cp($value, $expl_id, "expl")) {
                        $mon_msg = "La valeur  : " . $value["a"] . " n'a pas été reprise dans le champ personnalisé : " . $value["n"] . " car le champ n'existe pas";
                        affiche_mes_erreurs($mon_msg);
                    } else {
                        unset($info_999[$key]);
                    }
                }
            }
        }
    }
    // fin for
}