592e5d0bed2e2c87c34de710d836d99cf8284c8a
[lhc/web/www.git] / www / plugins-dist / medias / formulaires / changer_fichier_document.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2016 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
8 * *
9 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
10 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
11 \***************************************************************************/
12
13 if (!defined('_ECRIRE_INC_VERSION')) {
14 return;
15 }
16
17 function formulaires_changer_fichier_document_charger_dist($id_document) {
18 $valeurs = sql_fetsel('id_document,fichier,distant', 'spip_documents', 'id_document=' . intval($id_document));
19 if (!$valeurs) {
20 return array('editable' => false);
21 }
22
23 $charger = charger_fonction('charger', 'formulaires/joindre_document');
24 $valeurs = array_merge($valeurs, $charger($id_document, 0, '', 'choix'));
25
26 $valeurs['_hidden'] .= "<input name='id_document' value='$id_document' type='hidden' />";
27
28 return $valeurs;
29 }
30
31 function formulaires_changer_fichier_document_verifier_dist($id_document) {
32 $erreurs = array();
33 if (_request('copier_local')) {
34 } else {
35 $verifier = charger_fonction('verifier', 'formulaires/joindre_document');
36 $erreurs = $verifier($id_document);
37 }
38
39 return $erreurs;
40 }
41
42 function formulaires_changer_fichier_document_traiter_dist($id_document) {
43 if (_request('copier_local')) {
44 $copier_local = charger_fonction('copier_local', 'action');
45 $res = array('editable' => true);
46 if (($err = $copier_local($id_document)) === true) {
47 $res['message_ok'] = _T('medias:document_copie_locale_succes');
48 } else {
49 $res['message_erreur'] = $err;
50 }
51 } else {
52 // liberer le nom de l'ancien fichier pour permettre le remplacement par un fichier du meme nom
53 if ($ancien_fichier = sql_getfetsel('fichier', 'spip_documents', 'id_document=' . intval($id_document))
54 and @file_exists($f = get_spip_doc($ancien_fichier))
55 ) {
56 spip_unlink($f);
57 }
58 $traiter = charger_fonction('traiter', 'formulaires/joindre_document');
59 $res = $traiter($id_document);
60 }
61
62 return $res;
63 }