[PLUGINS] ~maj globale
[lhc/web/www.git] / www / plugins / formidable / puce_statut / formulaires_reponse.php
1 <?php
2
3 /**
4 * Gestion des puces d'action rapide de formulaires
5 *
6 * @package SPIP\Formidable\Puce_statut
7 **/
8
9 /**
10 * Gestion des puces statuts des formulaires
11 *
12 * Retourne le contenu d'une puce avec changement de statut possible
13 * si on en a l'autorisation, sinon simplement l'image de la puce
14 *
15 * @param int $id
16 * Identifiant de l'objet
17 * @param string $statut
18 * Statut actuel de l'objet
19 * @param int $id_parent
20 * Identifiant du parent, un formulaire
21 * @param string $type
22 * Type d'objet
23 * @param bool $ajax
24 * Indique s'il ne faut renvoyer que le coeur du menu car on est
25 * dans une requete ajax suite à un post de changement rapide
26 * @param bool $menu_rapide
27 * Indique si l'on peut changer le statut, ou si on l'affiche simplement
28 * @return string
29 * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
30 **/
31 function puce_statut_formulaires_reponse_dist($id, $statut, $id_parent, $type = 'article', $ajax = false, $menu_rapide = _ACTIVER_PUCE_RAPIDE) {
32
33 $src = statut_image($type, $statut);
34 if (!$src) {
35 return $src;
36 }
37
38 if (!$id
39 or !_SPIP_AJAX
40 or !$menu_rapide
41 or !autoriser('instituer', $type, $id)) {
42 $ajax_node ='';
43 } else {
44 $ajax_node = " class='imgstatut$type$id'";
45 }
46
47 $inser_puce = http_img_pack($src, statut_titre($type, $statut), $ajax_node);
48
49 if (!$ajax_node) {
50 return $inser_puce;
51 }
52
53 $table = table_objet_sql($type);
54 $desc = lister_tables_objets_sql($table);
55 if (!isset($desc['statut_textes_instituer'])) {
56 return $inser_puce;
57 }
58
59 $coord = array_flip(array_keys($desc['statut_textes_instituer']));
60 if (!isset($coord[$statut])) {
61 return $inser_puce;
62 }
63
64 $unit = 8/*widh de img*/+4/*padding*/;
65 $margin = 4; /* marge a gauche + droite */
66 $zero = 1 /*border*/ + $margin/2 + 2 /*padding*/;
67 $clip = $zero+ ($unit*$coord[$statut]);
68 if ($ajax) {
69 $width = $unit*count($desc['statut_textes_instituer'])+$margin;
70 $out = "<span class='puce_objet_fixe $type'>"
71 . $inser_puce
72 . '</span>'
73 . "<span class='puce_objet_popup $type statutdecal$type$id' style='width:{$width}px;margin-left:-{$clip}px;'>";
74 $i=0;
75 foreach ($desc['statut_textes_instituer'] as $s => $t) {
76 $out .= afficher_script_statut($id, $type, -$zero-$i++*$unit, statut_image($type, $s), $s, _T($t));
77 }
78 $out .= '</span>';
79 return $out;
80 } else {
81 $nom = 'puce_statut_';
82 $action = generer_url_ecrire('puce_statut_formulaires', '', true);
83 $action = "if (!this.puce_loaded) { this.puce_loaded = true; prepare_selec_statut(this, '$nom', '$type', '$id', '$action'); }";
84 $over = " onmouseover=\"$action\"";
85
86 $lang_dir = lang_dir(isset($GLOBALS['lang_objet']) ? $GLOBALS['lang_objet'] : '');
87 return "<span class='puce_objet $type' id='$nom$type$id' dir='$lang_dir'$over>"
88 . $inser_puce
89 . '</span>';
90 }
91 }