/**
  * Formulaire de saisie des suggestions multiples
  */
 function display_form()
 {
     global $dbh, $multi_sug_form, $charset, $msg, $sug_src;
     //On charge la liste des sources
     $req = "select * from suggestions_source order by libelle_source";
     $res = pmb_mysql_query($req, $dbh);
     $option = "<option value='0' selected>" . htmlentities($msg['empr_sugg_no_src'], ENT_QUOTES, $charset) . "</option>";
     while ($src = pmb_mysql_fetch_object($res)) {
         $option .= "<option value='" . $src->id_source . "' " . ($sug_src == $src->id_source ? 'selected' : '') . ">" . htmlentities($src->libelle_source, ENT_QUOTES, $charset) . "</option>";
     }
     if (!$this->liste_sugg) {
         $nb_lignes = 1;
         $multi_sug_form = str_replace('!!max_ligne!!', $nb_lignes, $multi_sug_form);
         $ligne = "\n\t\t\t\t<tr id='sugg_0'>\n\t\t\t\t\t<td><input type='texte' name='sugg_tit_0' id='sugg_tit_0' value=''  disabled /></td>\n\t\t\t\t\t<td><input type='texte' name='sugg_aut_0' id='sugg_aut_0' value='' disabled /></td>\n\t\t\t\t\t<td><input type='texte' name='sugg_edi_0' id='sugg_edi_0' value='' disabled /></td>\n\t\t\t\t\t<td><input type='texte' name='sugg_code_0' id='sugg_code_0' value='' disabled /></td>\n\t\t\t\t\t<td><input type='texte' name='sugg_prix_0' id='sugg_prix_0' value='' disabled /></td>\n\t\t\t\t\t<td><input type='texte' name='sugg_url_0' id='sugg_url_0' value='' disabled /></td>\n\t\t\t\t\t<td><textarea name='sugg_com_0' id='sugg_com_0' disabled ></textarea></td>\n\t\t\t\t\t<td><input type='texte' name='sugg_date_0' id='sugg_date_0' value='' disabled /></td>\n\t\t\t\t\t<td>\n\t\t\t\t\t\t<select id='sugg_src_0' name='sugg_src_0' disabled >\n\t\t\t\t\t\t\t{$option}\n\t\t\t\t\t\t</select>\n\t\t\t\t\t</td>\n\t\t\t\t\t<td><input type='texte' name='sugg_qte_0' id='sugg_qte_0' value='1' disabled /></td>\n\t\t\t\t\t<td id='act_btn_0'><input type='button' name='add_line_0' id='add_line_0' value='+' onclick=\"add_line(0);\"/></td>\n\t\t\t\t</tr>";
     } else {
         $liste = $this->liste_sugg;
         $this->ori_unimarc = microtime() . "_unimulti";
         for ($i = 0; $i < count($liste); $i++) {
             $ext = false;
             $notice_id = 0;
             if (strpos($liste[$i], 'es') !== false) {
                 $id_noti = str_replace('es', '', $liste[$i]);
                 $entrepots_localisations = array();
                 $entrepots_localisations_sql = "SELECT * FROM entrepots_localisations ORDER BY loc_visible DESC";
                 $res = pmb_mysql_query($entrepots_localisations_sql);
                 while ($row = pmb_mysql_fetch_array($res)) {
                     $entrepots_localisations[$row["loc_code"]] = array("libelle" => $row["loc_libelle"], "visible" => $row["loc_visible"]);
                 }
                 //Traitement de la notice uni
                 $uni = new suggestions_unimarc();
                 $uni->entrepot_to_unimarc($id_noti);
                 $uni->sugg_uni_num_notice = $id_noti;
                 $uni->sugg_uni_origine = $this->ori_unimarc;
                 $uni->save();
                 $aff = new notice_affichage_unimarc($id_noti, '', 0, 0, $entrepots_localisations);
                 $aff->fetch_data();
                 $titre = $aff->notice->tit1;
                 $auteur = $aff->auteurs_principaux ? $aff->auteurs_principaux : $aff->auteurs_tous;
                 $editeur = $aff->publishers[0]["name"];
                 $code = $aff->code;
                 $prix = $aff->prix;
                 $date = $aff->year;
                 $url = $aff->notice->lien ? $aff->notice->lien : ($aff->notice->eformat ? $aff->notice->eformat : ($aff->notice->lien_texte ? $aff->notice->lien_texte : ''));
                 $ext = true;
             } else {
                 $requete = "SELECT tit1 as titre, ed_name as editeur, CONCAT(author_name,' ',author_rejete) as auteur, prix, code, lien, year \n\t\t\t\t\tFROM notices LEFT JOIN responsability ON responsability_notice=notice_id \n\t\t\t\t\tLEFT JOIN authors ON responsability_author=author_id LEFT JOIN publishers ON ed1_id=ed_id\n\t\t\t\t\tWHERE notice_id=" . $liste[$i];
                 $result = pmb_mysql_query($requete, $dbh);
                 $sug = pmb_mysql_fetch_object($result);
                 $titre = $sug->titre;
                 $auteur = $sug->auteur;
                 $editeur = $sug->editeur;
                 $code = $sug->code;
                 $prix = $sug->prix;
                 $date = $sug->year;
                 $url = $sug->lien;
                 $notice_id = $liste[$i];
             }
             $ligne .= "<tr id='sugg_{$i}'>\n\t\t\t\t\t<td><input type='texte' name='sugg_tit_{$i}' id='sugg_tit_{$i}' value='" . htmlentities($titre, ENT_QUOTES, $charset) . "' /></td>\n\t\t\t\t\t<td><input type='texte' name='sugg_aut_{$i}' id='sugg_aut_{$i}' value='" . htmlentities($auteur, ENT_QUOTES, $charset) . "' /></td>\n\t\t\t\t\t<td><input type='texte' name='sugg_edi_{$i}' id='sugg_edi_{$i}' value='" . htmlentities($editeur, ENT_QUOTES, $charset) . "' /></td>\n\t\t\t\t\t<td><input type='texte' name='sugg_code_{$i}' id='sugg_code_{$i}' value='" . htmlentities($code, ENT_QUOTES, $charset) . "' /></td>\n\t\t\t\t\t<td><input type='texte' name='sugg_prix_{$i}' id='sugg_prix_{$i}' value='" . $prix . "' /></td>\n\t\t\t\t\t<td><input type='texte' name='sugg_url_{$i}' id='sugg_url_{$i}' value='" . htmlentities($url, ENT_QUOTES, $charset) . "' /></td>\n\t\t\t\t\t<td><textarea name='sugg_com_{$i}' id='sugg_com_{$i}'></textarea></td>\n\t\t\t\t\t<td><input type='texte' name='sugg_date_{$i}' id='sugg_date_{$i}' value='" . htmlentities($date, ENT_QUOTES, $charset) . "' /></td>\n\t\t\t\t\t<td>\n\t\t\t\t\t\t<select id='sugg_src_{$i}' name='sugg_src_{$i}'>\n\t\t\t\t\t\t\t{$option}\n\t\t\t\t\t\t</select>\n\t\t\t\t\t</td>\n\t\t\t\t\t<td><input type='texte' name='sugg_qte_{$i}' id='sugg_qte_{$i}' value='1' /></td>";
             if ($i == count($liste) - 1) {
                 $ligne .= "<td id='act_btn_{$i}'><input type='button' name='add_line_{$i}' id='add_line_{$i}' value='+' onclick=\"add_line({$i});\"/></td>";
             } else {
                 $ligne .= "<td id='act_btn_{$i}'><input type='button' name='del_line_{$i}' id='del_line_{$i}' value='X' onclick=\"del_line({$i});\"/></td>";
             }
             if ($ext) {
                 $ligne .= "<input type='hidden' name='id_unimarc_{$i}' id='id_unimarc_{$i}' value='" . $uni->sugg_uni_id . "'/> ";
             }
             if ($notice_id) {
                 $ligne .= "<input type='hidden' name='id_notice_{$i}' id='id_notice_{$i}' value='" . $notice_id . "' /> ";
             }
             $ligne .= "</tr>";
         }
         $multi_sug_form = str_replace('!!max_ligne!!', $i, $multi_sug_form);
     }
     $multi_sug_form = str_replace('!!ligne!!', $ligne, $multi_sug_form);
     return $multi_sug_form;
 }
 function traite_notice($notice_iso2709, $n_notice)
 {
     $notice = new iso2709_notices($notice_iso2709);
     $n_notice--;
     if (!$notice->error) {
         $this->liste_sugg[$n_notice]['code'] = $notice->fields['010'][0]['a'][0] ? $notice->fields['010'][0]['a'][0] : $notice->fields['011'][0]['a'][0];
         $this->liste_sugg[$n_notice]['prix'] = $notice->fields['010'][0]['d'][0];
         $this->liste_sugg[$n_notice]['titre'] = $notice->fields['200'][0]['a'][0];
         $this->liste_sugg[$n_notice]['editeur'] = $notice->fields['210'][0]['a'][0];
         $this->liste_sugg[$n_notice]['date'] = $notice->fields['210'][0]['d'][0];
         $this->liste_sugg[$n_notice]['auteur'] = $notice->fields['700'][0]['a'][0] ? $notice->fields['700'][0]['a'][0] : ($notice->fields['710'][0]['a'][0] ? $notice->fields['710'][0]['a'][0] : $notice->fields['701'][0]['a'][0] . ", " . $notice->fields['701'][0]['b'][0]);
         $this->liste_sugg[$n_notice]['url'] = $notice->fields['856'][0]['u'][0];
         //Enregistrement de la suggestion unimarc
         $uni = new suggestions_unimarc();
         $uni->sugg_uni_notice = $notice_iso2709;
         $uni->sugg_uni_num_notice = $n_notice;
         $uni->sugg_uni_origine = $this->ori_unimarc;
         $uni->save();
         $this->liste_sugg[$n_notice]['id_uni'] = $uni->sugg_uni_id;
     }
 }