function attach_docnum() { global $dbh, $chk, $ck_index, $pmb_indexation_docnum; for ($i = 0; $i < count($chk); $i++) { //On attache les documents numériques cochés $req = "select explnum_doc_nomfichier as nom ,explnum_doc_mimetype as mime,explnum_doc_data as data,explnum_doc_extfichier as ext\n\t\t\tfrom explnum_doc \n\t\t\tjoin explnum_doc_actions on num_explnum_doc=id_explnum_doc\n\t\t\tjoin demandes_actions on num_action=id_action\n\t\t\twhere id_explnum_doc='" . $chk[$i] . "'\n\t\t\tand num_explnum = 0\n\t\t\tand num_demande='" . $this->id_demande . "'\n\t\t\t"; $res = mysql_query($req, $dbh); if (mysql_num_rows($res)) { $expl = mysql_fetch_object($res); $req = "insert into explnum(explnum_notice,explnum_nom,explnum_nomfichier,explnum_mimetype,explnum_data,explnum_extfichier) values \n\t\t\t\t\t('" . $this->num_notice . "','" . addslashes($expl->nom) . "','" . addslashes($expl->nom) . "','" . addslashes($expl->mime) . "','" . addslashes($expl->data) . "','" . addslashes($expl->ext) . "')"; mysql_query($req, $dbh); $id_explnum = mysql_insert_id(); $req = "update explnum_doc_actions set num_explnum='" . $id_explnum . "' where num_explnum_doc='" . $chk[$i] . "'"; mysql_query($req, $dbh); if ($ck_index[$i] && $pmb_indexation_docnum) { $expl = new explnum($id_explnum); $expl->indexer_docnum(); } } } //On désattache les autres if ($chk) { $req = "select id_explnum_doc from explnum_doc where id_explnum_doc not in ('" . implode('\',\'', $chk) . "')"; $res = mysql_query($req, $dbh); while ($expl = mysql_fetch_object($res)) { $req = "delete e from explnum e \n\t\t\t\t\tjoin explnum_doc_actions on num_explnum=explnum_id \n\t\t\t\t\twhere num_explnum_doc='" . $expl->id_explnum_doc . "'"; mysql_query($req, $dbh); $req = "update explnum_doc_actions set num_explnum='0' where num_explnum_doc='" . $expl->id_explnum_doc . "'"; mysql_query($req, $dbh); } } else { $req = "select id_explnum_doc\n\t\t\t\t\tfrom explnum_doc \n\t\t\t\t\tjoin explnum_doc_actions on num_explnum_doc=id_explnum_doc\n\t\t\t\t\tjoin demandes_actions on num_action=id_action\n\t\t\t\t\twhere num_explnum != 0\n\t\t\t\t\tand num_demande='" . $this->id_demande . "'"; $res = mysql_query($req, $dbh); while ($expl = mysql_fetch_object($res)) { $req = "delete e from explnum e \n\t\t\t\t\tjoin explnum_doc_actions on num_explnum=explnum_id \n\t\t\t\t\twhere num_explnum_doc='" . $expl->id_explnum_doc . "'"; mysql_query($req, $dbh); $req = "update explnum_doc_actions set num_explnum='0' where num_explnum_doc='" . $expl->id_explnum_doc . "'"; mysql_query($req, $dbh); } } }