From 44166c8970d5a98a955e84ffd7702ed37e619f05 Mon Sep 17 00:00:00 2001
From: Fil <fil@rezo.net>
Date: Thu, 21 Mar 2002 11:49:58 +0000
Subject: [PATCH] documents attaches corriges finis. Y compris debut de
 personnalisation de la presentation des docs (enfin, il y a des switches pour
 interdire d'afficher, par exemple, le type de doc ou la taille en pixels...)
 Attention Antoine : j'en ai besoin tout de suite sur le Diplo, donc ca passe
 en prod. Ne pas tout casser SVP.

---
 ecrire/article_documents.php3 | 43 ++++++++++++++++++++++++-----------
 ecrire/inc_documents.php3     | 36 ++++++++++++++++++-----------
 ecrire/inc_texte.php3         | 15 ++++++++----
 spip_image.php3               |  8 ++++---
 4 files changed, 69 insertions(+), 33 deletions(-)

diff --git a/ecrire/article_documents.php3 b/ecrire/article_documents.php3
index 83c568475d..c8aaa0d3a2 100644
--- a/ecrire/article_documents.php3
+++ b/ecrire/article_documents.php3
@@ -46,10 +46,18 @@ if ($modif_document == 'oui') {
 	mysql_query("UPDATE spip_documents SET titre=\"$titre\", descriptif=\"$descriptif\" WHERE id_document=$id_document");
 }
 
-if ($ajouter_vignette == 'oui') {
+// transformer en vignette/document
+if ($transformer_image == 'document') {
 	mysql_query("UPDATE spip_documents SET mode='document' WHERE id_document=$id_document");
+} else if ($transformer_image == 'vignette') {
+	// est-ce qu'on met aussi id_vignette=0 ? (Non : on garde une trace de l'id_vignette en cas
+	// d'aller-retour document -> vignette -> document
+	mysql_query("UPDATE spip_documents SET mode='vignette' WHERE id_document=$id_document");
 }
 
+//
+// Affichage
+//
 $query = "SELECT titre FROM spip_articles WHERE id_article = $id_article";
 $result = mysql_query($query);
 if ($art = mysql_fetch_object($result)) {
@@ -76,6 +84,7 @@ if ($documents_lies) {
 	echo "<tr bgcolor='$couleur_foncee'>\n";
 	echo "<td width='100%'><font face='Verdana,Arial,Helvetica,sans-serif' size='4' color='#ffffff'>";
 	echo "Documents li&eacute;s &agrave l'article".$lien_art;
+	$lien_art='';
 	echo "</td></tr>\n";
 
 	reset($documents_lies);
@@ -85,20 +94,30 @@ if ($documents_lies) {
 		echo "</td></tr>\n";
 	}
 	echo "<tr><td height='10'>&nbsp;</td></tr>\n";
-}
 
+	$res = mysql_query("SELECT DISTINCT id_vignette FROM spip_documents ".
+		"WHERE id_document in (".join(',', $documents_lies).")");
+	while ($v = mysql_fetch_object($res))
+		$vignettes[] = $v->id_vignette;
+
+	$docs_exclus = ereg_replace('^,','',join(',', $vignettes).','.join(',', $documents_lies));
+
+	if ($docs_exclus)
+		$docs_exclus = "AND l.id_document NOT IN ($docs_exclus) ";
+
+}
 
-if ($documents_lies) $docs_exclus = "AND l.id_document NOT IN (".join(',', $documents_lies).") ";
 $query = "SELECT #cols FROM #table, spip_documents_articles AS l ".
-	"WHERE l.id_article=$id_article AND l.id_document=#table.id_document ".$docs_exclus.
-	"AND #table.mode='vignette' AND #table.titre!='' ORDER BY #table.titre";
+		"WHERE l.id_article=$id_article AND l.id_document=#table.id_document ".$docs_exclus.
+		"AND #table.mode='vignette' AND #table.titre!='' ORDER BY #table.titre";
 
 $images_liees = fetch_document($query);
 
 if ($images_liees) {
 	echo "<tr bgcolor='$couleur_foncee'>\n";
 	echo "<td width='100%'><font face='Verdana,Arial,Helvetica,sans-serif' size='4' color='#ffffff'>";
-	echo "Images affichables dans l'article";
+	echo "Images affichables dans l'article".$lien_art;
+	$lien_art = '';
 	echo "</td></tr>\n";
 
 	reset($images_liees);
@@ -116,13 +135,11 @@ if ($images_liees) {
 //
 
 
-echo "<tr><td height='5'>&nbsp;</td></tr>\n";
-
-//echo "<tr bgcolor='$couleur_foncee'>\n";
-echo "<tr bgcolor='#EEEECC'>\n";
-echo "<td><font face='Verdana,Arial,Helvetica,sans-serif' size='4' color='#000000'>";
-echo "Ajouter une image ou un document";
-echo "</td></tr>\n";
+echo "<tr bgcolor='$couleur_foncee'>\n";
+echo "<td width='100%'><font face='Verdana,Arial,Helvetica,sans-serif' size='4' color='#ffffff'>";
+echo "<i>Ajouter une image ou un document &agrave; l'article".$lien_art;
+$lien_art = '';
+echo "</i></td></tr>\n";
 echo "</td></tr></table>\n";
 
 echo debut_boite_info();
diff --git a/ecrire/inc_documents.php3 b/ecrire/inc_documents.php3
index ba9f057f9f..29b44e27e0 100644
--- a/ecrire/inc_documents.php3
+++ b/ecrire/inc_documents.php3
@@ -55,8 +55,10 @@ function texte_vignette($largeur_vignette, $hauteur_vignette, $fichier_vignette)
 function afficher_upload($link, $intitule, $inclus = '') {
 	global $this_link, $connect_statut;
 
-	if (!$link->getVar('redirect'))
-		$link->addVar('redirect', $this_link->getUrl());
+	if (!$link->getVar('redirect')) {
+		$my_link = new Link("article_documents.php3");	// faute de mieux pour l'instant (Fil)
+		$link->addVar('redirect', $my_link->getUrl());
+	}
 
 	echo "<font face='verdana, arial, helvetica, sans-serif' size='2'>\n";
 	echo $link->getForm('POST', '', 'multipart/form-data');
@@ -177,17 +179,26 @@ function afficher_document($id_document, $id_doc_actif = 0) {
 		echo "<font size='2'><b>IMAGE</b></font><br>\n";
 		echo texte_vignette($largeur, $hauteur, $fichier);
 		echo "<font face='verdana, arial, helvetica, sans-serif' size='1'><br>$largeur x $hauteur pixels<br><br></font>\n";
-		echo $raccourci_doc;
+
+		if ($mode == 'vignette')// le raccourci pour une image-document est propose avec la vignette
+			echo $raccourci_doc;
+
 		echo "</td>\n";
 	}
 
-	if ($mode == 'vignette') {
-		$link = new Link();
-		$link->addVar('ajouter_vignette','oui');
-		$link->addVar('id_document',$id_document);
-		$link_ajouter = "<font size='1'>[<b><a ".$link->getHref().">AJOUTER UNE VIGNETTE</a></b>]</font>\n";
-	} else
-		unset($link_ajouter);
+	if ($type_inclus == 'image') {
+		if ($mode == 'vignette') {
+			$link = new Link();
+			$link->addVar('transformer_image','document');
+			$link->addVar('id_document',$id_document);
+			$link_transformer = "<font size='1'>[<b><a ".$link->getHref().">Transformer en document</a></b>]</font>\n";
+		} else if ($mode == 'document') {
+			$link = new Link();
+			$link->addVar('transformer_image','vignette');
+			$link->addVar('id_document',$id_document);
+			$link_transformer = "<font size='1'>[<b><a ".$link->getHref().">Transformer en image affichable</a></b>]</font>\n";
+		}
+	}
 
 	//
 	// Afficher le document en tant que tel
@@ -218,9 +229,9 @@ function afficher_document($id_document, $id_doc_actif = 0) {
 	echo "</textarea>\n";
 
 	echo "<p align='right'>";
-	echo $link_ajouter;
 	echo "<input class='fondo' TYPE='submit' NAME='Valider' VALUE='Valider'>";
 	echo "</p>";
+	if ($link_transformer) echo "<p align='right'>$link_transformer</p>";
 
 	echo "</form>";
 	echo "</font>";
@@ -251,7 +262,6 @@ function afficher_document($id_document, $id_doc_actif = 0) {
 			echo "[<a href='../spip_image.php3?redirect=".urlencode("article_documents.php3")."&id_document=$id_document&id_article=$id_article&hash_id_auteur=$connect_id_auteur&hash=$hash&doc_supp=$id_vignette'>";
 			echo "supprimer la vignette";
 			echo "</a>]</font><br>\n";
-	
 			echo $raccourci_doc;
 		}
 		else {
@@ -274,7 +284,7 @@ function afficher_document($id_document, $id_doc_actif = 0) {
 			$link->addVar('hash_id_auteur', $connect_id_auteur);
 			$link->addVar('hash', $hash);
 	
-			afficher_upload($link, 'Charger une vignette sp&eacute;cifique&nbsp;:', 'image');
+			afficher_upload($link, 'Charger une vignette&nbsp;:', 'image');
 			echo "</div>\n";
 		}
 
diff --git a/ecrire/inc_texte.php3 b/ecrire/inc_texte.php3
index ef6fce4538..3f18df0403 100644
--- a/ecrire/inc_texte.php3
+++ b/ecrire/inc_texte.php3
@@ -19,6 +19,13 @@ $GLOBALS['ouvre_note'] = '[';
 $GLOBALS['ferme_note'] = '] ';
 $GLOBALS['les_notes']  = '';
 $GLOBALS['compt_note'] = 0;
+
+// switches pour l'affichage des documents (peut mieux faire !)
+$GLOBALS['doc_affiche_titre'] = true;
+$GLOBALS['doc_affiche_descriptif'] = true;
+$GLOBALS['doc_affiche_fichier'] = true;
+$GLOBALS['doc_affiche_largeurhauteur'] = true;
+
 if (file_exists("puce.gif")) {
 	$imgsize = getimagesize('puce.gif');
 	$GLOBALS['puce'] = "<img src='puce.gif' align='top' alt='- ' ".$imgsize[3]." border='0'> ";
@@ -313,10 +320,10 @@ function integre_image($id_document, $align, $affichage_detaille = false) {
 			$retour .= "<tr><td align='center'>\n<div class='spip_documents'>\n";
 			$retour .= $vignette;
 
-			if ($titre) $retour .= "<br><b>$titre</b>";
-			if ($descriptif) $retour .= "<br>$descriptif";
-			if ($fichier) $retour .= "<br>$type - $taille_ko&nbsp;ko";
-			if ($largeur && $hauteur) $retour .= "<br>$largeur x $hauteur pixels";
+			if ($GLOBALS['doc_affiche_titre'] AND $titre) $retour .= "<br><b>$titre</b>";
+			if ($GLOBALS['doc_affiche_descriptif'] AND $descriptif) $retour .= "<br>$descriptif";
+			if ($GLOBALS['doc_affiche_fichier'] AND $fichier) $retour .= "<br>$type - $taille_ko&nbsp;ko";
+			if ($GLOBALS['doc_affiche_largeurhauteur'] AND $largeur AND $hauteur) $retour .= "<br>$largeur x $hauteur pixels";
 			
 			$retour .= "</div>\n</td></tr>\n</table>\n";
 		}
diff --git a/spip_image.php3 b/spip_image.php3
index 193643dbb4..233a73ea17 100644
--- a/spip_image.php3
+++ b/spip_image.php3
@@ -97,8 +97,8 @@ function ajout_doc($orig, $source, $dest, $mode, $id_document) {
 
 	if ($mode == 'vignette') {
 		$id_document_lie = $id_document;
-		$query = "UPDATE spip_documents SET mode='document' where id_document=$id_document";
-		mysql_query($query);
+		$query = "UPDATE spip_documents SET mode='document' where id_document=$id_document_lie";
+		mysql_query($query); // requete inutile a mon avis (Fil)...
 		$id_document = 0;
 	}
 	if (!$id_document) {
@@ -149,9 +149,11 @@ function ajout_doc($orig, $source, $dest, $mode, $id_document) {
 	$query = "UPDATE spip_documents SET $update taille='$taille', largeur='$largeur', hauteur='$hauteur', fichier='$dest_path' ".
 		"WHERE id_document=$id_document";
 	mysql_query($query);
+
 	if ($id_document_lie) {
 		$query = "UPDATE spip_documents SET id_vignette=$id_document WHERE id_document=$id_document_lie";
 		mysql_query($query);
+		$id_document = $id_document_lie; // pour que le 'return' active le bon doc.
 	}
 
 	return array (true,$id_document) ; // on veut bien effacer le fichier s'il est dans ftp/upload/
@@ -224,7 +226,7 @@ $redirect_url = "ecrire/" . $vars["redirect"];
 $link = new Link($redirect_url);
 reset($vars);
 while (list ($key, $val) = each ($vars)) {
-	if (!ereg("^(redirect|image.*|hash.*|ajout.*|doc.*|id_document)$", $key)) {
+	if (!ereg("^(redirect|image.*|hash.*|ajout.*|doc.*|id_document|transformer.*)$", $key)) {
 		$link->addVar($key, $val);
 	}
 }
-- 
GitLab