[SPIP] +2.1.12
[velocampus/web/www.git] / www / ecrire / inc / editer_auteurs.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2011 *
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')) return;
14
15 include_spip('inc/presentation');
16 include_spip('inc/actions');
17
18 // L'ajout d'un auteur se fait par mini-navigateur dans la fourchette:
19 define('_SPIP_SELECT_MIN_AUTEURS', 30); // en dessous: balise Select
20 define('_SPIP_SELECT_MAX_AUTEURS', 30); // au-dessus: saisie + return
21
22 // http://doc.spip.org/@inc_editer_auteurs_dist
23 function inc_editer_auteurs_dist($type, $id, $flag, $cherche_auteur, $ids, $titre_boite = NULL, $script_edit_objet = NULL) {
24
25 $arg_ajax = "&id_{$type}=$id&type=$type";
26 if ($script_edit_objet===NULL) $script_edit_objet = $type.'s';
27 if ($titre_boite===NULL)
28 $titre_boite = _T('texte_auteurs'). aide("artauteurs");
29 else
30 $arg_ajax.= "&titre=".urlencode($titre_boite);
31
32 $aff_les_auteurs = afficher_auteurs_objet($type, $id, $flag, '', $script_edit_objet, $arg_ajax);
33
34 if ($flag) {
35 $futurs = ajouter_auteurs_objet($type, $id, '',$script_edit_objet, $arg_ajax);
36 } else $futurs = '';
37
38 $ldap = isset($GLOBALS['meta']['ldap_statut_import']) ?
39 $GLOBALS['meta']['ldap_statut_import'] : '';
40
41 return editer_auteurs_objet($type, $id, $flag, $cherche_auteur, $ids, $aff_les_auteurs, $futurs, $ldap,$titre_boite,$script_edit_objet, $arg_ajax);
42 }
43
44 // http://doc.spip.org/@editer_auteurs_objet
45 function editer_auteurs_objet($type, $id, $flag, $cherche_auteur, $ids, $les_auteurs, $futurs, $statut, $titre_boite,$script_edit_objet, $arg_ajax)
46 {
47 global $spip_lang_left, $spip_lang_right;
48
49 $bouton_creer_auteur = $GLOBALS['connect_toutes_rubriques'];
50 $clic = _T('icone_creer_auteur');
51
52 //
53 // complement de action/editer_auteurs.php pour notifier la recherche d'auteur
54 //
55 if ($cherche_auteur) {
56
57 $reponse ="<div style='text-align: $spip_lang_left'>"
58 . debut_boite_info(true)
59 . rechercher_auteurs_objet($cherche_auteur, $ids, $type, $id,$script_edit_objet, $arg_ajax);
60
61 if ($type=='article' && $bouton_creer_auteur) { // pas generique pour le moment
62
63 $legende = generer_url_ecrire("auteur_infos", "new=oui&lier_id_article=$id");
64 if (isset($cherche_auteur))
65 $legende = parametre_url($legende, 'nom', $cherche_auteur);
66 $legende = parametre_url($legende, 'redirect',
67 generer_url_ecrire('articles', "id_article=$id", '&'));
68
69 $reponse .="<div style='width: 200px;'>"
70 . icone_horizontale($clic, $legende, "redacteurs-24.gif", "creer.gif", false)
71 . "</div> ";
72
73 $bouton_creer_auteur = false;
74 }
75
76 $reponse .= fin_boite_info(true)
77 . '</div>';
78 } else $reponse ='';
79
80 $reponse .= $les_auteurs;
81
82 //
83 // Ajouter un auteur
84 //
85
86 $res = '';
87 if ($flag) {
88
89 if ($type=='article' && $bouton_creer_auteur) { // pas generique pour le moment
90
91 $legende = generer_url_ecrire("auteur_infos", "new=oui&lier_id_article=$id");
92 if (isset($cherche_auteur))
93 $legende = parametre_url($legende, 'nom', $cherche_auteur);
94 $legende = parametre_url($legende, 'redirect',
95 generer_url_ecrire('articles', "id_article=$id", '&'));
96
97 $clic = "<span class='verdana1'><b>$clic</b></span>";
98 $res = icone_horizontale_display($clic, $legende, "redacteurs-24.gif", "creer.gif", false);
99 }
100
101 $res = "<div style='float:$spip_lang_right; width:280px;position:relative;display:inline;'>"
102 . $futurs
103 ."</div>\n"
104 . $res;
105 }
106
107 $idom = "auteurs_$type" . "_$id";
108 $bouton = bouton_block_depliable($titre_boite,$flag ?($flag === 'ajax'):-1,$idom);
109 $res = debut_cadre_enfonce("auteur-24.gif", true, "", $bouton)
110 . $reponse
111 . debut_block_depliable($flag === 'ajax',$idom)
112 . $res
113 . fin_block()
114 . fin_cadre_enfonce(true);
115
116 return ajax_action_greffe("editer_auteurs", $id, $res);
117 }
118
119 // Retourne les auteurs attaches a l'objet $id de type $type
120 // ou rien s'il y en a trop
121
122 // http://doc.spip.org/@determiner_auteurs_objet
123 function determiner_auteurs_objet($type, $id, $cond='', $limit=200)
124 {
125 if (!preg_match(',^[a-z]*$,',$type)) return array();
126
127 $jointure = 'spip_' . table_jointure('auteur', $type);
128 $cond = "id_{$type}=".sql_quote($id) . ($cond ? " AND $cond" : '');
129 if (sql_countsel($jointure, $cond) > $limit)
130 return array();
131 else return array_map('array_shift', sql_allfetsel("id_auteur", $jointure, $cond));
132 }
133
134 // http://doc.spip.org/@determiner_non_auteurs
135 function determiner_non_auteurs($type, $id, $andcond='')
136 {
137 return auteurs_autorises(determiner_auteurs_objet($type, $id, $andcond));
138 }
139
140 // http://doc.spip.org/@rechercher_auteurs_objet
141 function rechercher_auteurs_objet($cherche_auteur, $ids, $type, $id, $script_edit_objet, $arg_ajax)
142 {
143 if (!$ids) {
144 return "<b>"._T('texte_aucun_resultat_auteur', array('cherche_auteur' => $cherche_auteur)).".</b><br />";
145 }
146 elseif ($ids == -1) {
147 return "<b>"._T('texte_trop_resultats_auteurs', array('cherche_auteur' => $cherche_auteur))."</b><br />";
148 }
149 elseif (preg_match('/^\d+$/',$ids)) {
150
151 $nom = sql_getfetsel("nom", "spip_auteurs", "id_auteur=$ids");
152 return "<b>"._T('texte_ajout_auteur')."</b><br /><ul><li><span class='verdana1 spip_small'><b><span class='spip_medium'>".typo($nom)."</span></b></span></li></ul>";
153 }
154 else {
155 $ids = preg_replace('/[^0-9,]/','',$ids); // securite
156 $result = sql_select("*", "spip_auteurs", "id_auteur IN ($ids)", "", "nom");
157
158 $res = "<b>"
159 . _T('texte_plusieurs_articles', array('cherche_auteur' => $cherche_auteur))
160 . "</b><br />"
161 . "<ul class='verdana1'>";
162 while ($row = sql_fetch($result)) {
163 $id_auteur = $row['id_auteur'];
164 $nom_auteur = $row['nom'];
165 $email_auteur = $row['email'];
166 $bio_auteur = $row['bio'];
167
168 $res .= "<li><b>".typo($nom_auteur)."</b>";
169
170 if ($email_auteur) $res .= " ($email_auteur)";
171
172 $res .= " | "
173 . ajax_action_auteur('editer_auteurs', "$id,$type,$id_auteur",$script_edit_objet,"id_{$type}=$id", array(_T('lien_ajouter_auteur')),$arg_ajax);
174
175 if (trim($bio_auteur)) {
176 $res .= "<br />".couper(propre($bio_auteur), 100)."\n";
177 }
178 $res .= "</li>\n";
179 }
180 $res .= "</ul>";
181 return $res;
182 }
183 }
184
185 // http://doc.spip.org/@afficher_auteurs_objet
186 function afficher_auteurs_objet($type, $id, $edit, $cond, $script, $arg_ajax)
187 {
188
189 $from = table_jointure('auteur', $type);
190 if (!$from) return '' ; // securite
191 $from = "spip_{$from}";
192 $where = "id_{$type}=".sql_quote($id) . ($cond ? " AND $cond" : '');
193
194 $presenter_liste = charger_fonction('presenter_liste', 'inc');
195
196 $requete = array('SELECT' => "id_auteur", 'FROM' => $from, 'WHERE' => $where);
197 $tmp_var = "editer_auteurs-$id";
198 $url = generer_url_ecrire('editer_auteurs',$arg_ajax);
199
200 // charger ici meme si pas d'auteurs
201 // car inc_formater_auteur peut aussi redefinir
202 // determiner_non_auteurs qui sert plus loin
203 if (!$formater = charger_fonction("formater_auteur_$type", 'inc',true))
204 $formater = charger_fonction('formater_auteur', 'inc');
205
206 $retirer = array(_T('lien_retirer_auteur')."&nbsp;". http_img_pack('croix-rouge.gif', "X", " class='puce' style='vertical-align: bottom;'"));
207
208 $styles = array(array('arial11', 14), array('arial2'), array('arial11'), array('arial11'), array('arial11'), array('arial1'));
209
210 $tableau = array(); // ne sert pas
211 $f = function_exists($edit) ? $edit : 'ajouter_auteur_un';
212 return $presenter_liste($requete, $f, $tableau, array($formater, $retirer, $arg_ajax, $edit, $id, $type, $script), false, $styles, $tmp_var, '','', $url);
213 }
214
215 // http://doc.spip.org/@ajouter_auteur_un
216 function ajouter_auteur_un($row, $own) {
217 global $connect_statut, $connect_id_auteur;
218 list($formater, $retirer, $arg_ajax, $flag, $id, $type, $script_edit) = $own;
219
220 $id_auteur = $row['id_auteur'];
221 $vals = $formater($id_auteur);
222 $voir = ($flag AND ($connect_id_auteur != $id_auteur OR $connect_statut == '0minirezo'));
223 if ($voir) {
224 $vals[] = ajax_action_auteur('editer_auteurs', "$id,$type,-$id_auteur", $script_edit, "id_{$type}=$id", $retirer, $arg_ajax);
225 } else $vals[] = "";
226 return $vals;
227 }
228
229 // http://doc.spip.org/@ajouter_auteurs_objet
230 function ajouter_auteurs_objet($type, $id, $cond_les_auteurs,$script_edit, $arg_ajax)
231 {
232 if (!$determiner_non_auteurs = charger_fonction('determiner_non_auteurs_'.$type,'inc',true))
233 $determiner_non_auteurs = 'determiner_non_auteurs';
234
235 $cond = $determiner_non_auteurs($type, $id, $cond_les_auteurs);
236 $all = objet_auteur_select($cond);
237 if (!$all) return '';
238 $idom = "auteur_$type" . "_$id";
239 $new = $idom . '_new';
240 $menu = $idom . '_sel';
241 $js = "findObj_forcer('$menu').style.visibility='visible';";
242
243 $text = "<span class='verdana1'><label for='$new'><b>"
244 . _T('titre_cadre_ajouter_auteur')
245 . "</b></label></span>\n";
246
247 if (!is_numeric($all)) {
248 $sel = "$text<select name='$new' id='$new' size='1' style='width:150px;' onchange=\"$js\">$all</select>";
249 $clic = _T('bouton_ajouter');
250 } else if ((_SPIP_AJAX < 1) OR ($all >= _SPIP_SELECT_MAX_AUTEURS)) {
251 $sel = "$text <input type='text' name='cherche_auteur' id='$new' onclick=\"$js\" value='' size='20' />";
252 $clic = _T('bouton_chercher');
253 } else {
254 $sel = selecteur_auteur_ajax($type, $id, $js, $text, $idom);
255 $clic = _T('bouton_ajouter');
256 }
257
258 return ajax_action_post('editer_auteurs', "$id,$type", $script_edit, "id_{$type}=$id", $sel, $clic, " class='visible_au_chargement' id='$menu'",'', $arg_ajax);
259 }
260
261 // http://doc.spip.org/@objet_auteur_select
262 function objet_auteur_select($cond)
263 {
264 $count = sql_countsel('spip_auteurs', $cond);
265 if (!$count) return '';
266 if ($count > _SPIP_SELECT_MIN_AUTEURS) return $count;
267 $statut_old = '';
268 $statuts = $GLOBALS['liste_des_statuts'];
269 $res = sql_allfetsel('*', 'spip_auteurs', $cond, '', "statut, nom");
270 foreach ($res as $k => $row) {
271 $statut = array_search($row["statut"], $statuts);
272 $id_auteur = $row["id_auteur"];
273 $email = $row["email"];
274 if (!autoriser('voir', 'auteur'))
275 if ($p = strpos($email, '@'))
276 $email = substr($email, 0, $p).'@...';
277 if ($email)
278 $email = " ($email)";
279 if ($statut != $statut_old) {
280 $opt = "</optgroup>\n<optgroup class='option_separateur_statut_auteur' label='" . _T($statut) . "'>";
281 $statut_old = $statut;
282 } else $opt = '';
283
284 $res[$k]= $opt
285 . "\n<option class='option_auteur' value='$id_auteur'>"
286 . supprimer_tags(couper(typo($row["nom"] . $email), 40))
287 . "</option>";
288 }
289 return "<optgroup label=''><option value='0'>"
290 . _T('bouton_choisir')
291 . '</option>'
292 . join('', $res)
293 . "\n</optgroup>";
294 }
295
296 // http://doc.spip.org/@selecteur_auteur_ajax
297 function selecteur_auteur_ajax($type, $id, $js, $text, $idom='')
298 {
299 include_spip('inc/chercher_rubrique');
300 $idom2 = $idom . '_new';
301 $idom1 = $idom . '_div';
302 $url = generer_url_ecrire('selectionner_auteur',"id_article=$id&type=$type");
303 return $text . construire_selecteur($url, $js, $idom1, $idom2, ' type="hidden"');
304 }
305 ?>