3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2007 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
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 \***************************************************************************/
13 if (!defined("_ECRIRE_INC_VERSION")) return;
15 include_spip('inc/presentation');
16 include_spip('inc/actions');
18 // L'ajout d'un auteur se fait par mini-navigateur dans la fourchette:
19 define('_SPIP_SELECT_MIN_AUTEURS', 10); // en dessous: balise Select
20 define('_SPIP_SELECT_MAX_AUTEURS', 100); // au-dessus: saisie + return
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
) {
25 $arg_ajax = "&id_{$type}=$id";
26 if ($script_edit_objet===NULL
) $script_edit_objet = $type.'s';
27 if ($titre_boite===NULL
)
28 $titre_boite = _T('texte_auteurs'). aide("artauteurs");
30 $arg_ajax.= "&titre=".urlencode($titre_boite);
33 $cond_les_auteurs = "";
34 $aff_les_auteurs = afficher_auteurs_objet($type, $id, $flag, $cond_les_auteurs, $script_edit_objet, $arg_ajax);
36 if ($flag AND $options == 'avancees') {
37 $futurs = ajouter_auteurs_objet($type, $id, $cond_les_auteurs,$script_edit_objet, $arg_ajax);
40 $ldap = isset($GLOBALS['meta']['ldap_statut_import']) ?
41 $GLOBALS['meta']['ldap_statut_import'] : '';
43 return editer_auteurs_objet($type, $id, $flag, $cherche_auteur, $ids, $aff_les_auteurs, $futurs, $ldap,$titre_boite,$script_edit_objet, $arg_ajax);
46 // http://doc.spip.org/@editer_auteurs_objet
47 function editer_auteurs_objet($type, $id, $flag, $cherche_auteur, $ids, $les_auteurs, $futurs, $statut, $titre_boite,$script_edit_objet, $arg_ajax)
49 global $spip_lang_left, $spip_lang_right, $options;
51 $bouton_creer_auteur = $GLOBALS['connect_toutes_rubriques'];
52 $clic = _T('icone_creer_auteur');
55 // complement de action/editer_auteurs.php pour notifier la recherche d'auteur
57 if ($cherche_auteur) {
59 $reponse ="<div style='text-align: $spip_lang_left'>"
60 . debut_boite_info(true
)
61 . rechercher_auteurs_objet($cherche_auteur, $ids, $type, $id,$script_edit_objet, $arg_ajax);
63 if ($type=='article' && $bouton_creer_auteur) { // pas generique pour le moment
65 $legende = generer_url_ecrire("auteur_infos", "new=oui&lier_id_article=$id");
66 $legende = parametre_url($legende, 'nom', $cherche_auteur);
67 $legende = parametre_url($legende, 'redirect',
68 generer_url_ecrire('articles', "id_article=$id", '&'));
70 $reponse .="<div style='width: 200px;'>"
71 . icone_horizontale($clic, $legende, "redacteurs-24.gif", "creer.gif", false
)
74 $bouton_creer_auteur = false
;
77 $reponse .= fin_boite_info(true
)
81 $reponse .= $les_auteurs;
88 if ($flag AND $options == 'avancees') {
90 if ($type=='article' && $bouton_creer_auteur) { // pas generique pour le moment
92 $legende = generer_url_ecrire("auteur_infos", "new=oui&lier_id_article=$id");
93 $legende = parametre_url($legende, 'nom', $cherche_auteur);
94 $legende = parametre_url($legende, 'redirect',
95 generer_url_ecrire('articles', "id_article=$id", '&'));
97 $clic = "<span class='verdana1'><b>$clic</b></span>";
98 $res = "<div style='width:170px;'>"
99 . icone_horizontale($clic, $legende, "redacteurs-24.gif", "creer.gif", false
)
103 $res = "<div style='float:$spip_lang_right; width:280px;position:relative;display:inline;'>"
111 : (($flag === 'ajax')
112 ?
bouton_block_visible("auteurs$type")
113 : bouton_block_invisible("auteurs$type")))
116 $res = '<div><div> </div>' // pour placer le gif patienteur
117 . debut_cadre_enfonce("auteur-24.gif", true
, "", $bouton)
119 . ($flag === 'ajax' ?
120 debut_block_visible("auteurs$type") :
121 debut_block_invisible("auteurs$type"))
124 . fin_cadre_enfonce(true
)
127 return ajax_action_greffe("editer_auteurs-$id", $res);
130 // http://doc.spip.org/@determiner_auteurs_objet
131 function determiner_auteurs_objet($type, $id, $cond='', $limit='')
133 $les_auteurs = array();
134 if (!preg_match(',^[a-z]*$,',$type)) return $les_auteurs;
136 $result = spip_query("SELECT id_auteur FROM spip_auteurs_{$type}s WHERE id_{$type}="._q($id)
137 . ($cond ?
" AND $cond" : '')
138 . ($limit?
" LIMIT $limit": '')
143 // http://doc.spip.org/@determiner_non_auteurs
144 function determiner_non_auteurs($type, $id, $cond_les_auteurs, $order)
147 $res = determiner_auteurs_objet($type, $id, $cond_les_auteurs);
148 if (spip_num_rows($res)<200){ // probleme de performance au dela, on ne filtre plus
149 while ($row = spip_fetch_array($res))
150 $cond .= ",".$row['id_auteur'];
153 $cond = "id_auteur NOT IN (" . substr($cond,1) . ') AND ';
155 return spip_query("SELECT * FROM spip_auteurs WHERE $cond" . "statut!='5poubelle' AND statut!='6forum' AND statut!='nouveau' ORDER BY $order");
158 // http://doc.spip.org/@rechercher_auteurs_objet
159 function rechercher_auteurs_objet($cherche_auteur, $ids, $type, $id, $script_edit_objet, $arg_ajax)
162 return "<b>"._T('texte_aucun_resultat_auteur', array('cherche_auteur' => $cherche_auteur)).".</b><br />";
164 elseif ($ids == -1) {
165 return "<b>"._T('texte_trop_resultats_auteurs', array('cherche_auteur' => $cherche_auteur))."</b><br />";
167 elseif (preg_match('/^\d+$/',$ids)) {
169 $row = spip_fetch_array(spip_query("SELECT nom FROM spip_auteurs WHERE id_auteur=$ids"));
170 return "<b>"._T('texte_ajout_auteur')."</b><br /><ul><li><span class='verdana1 spip_small'><b><span class='spip_medium'>".typo($row['nom'])."</span></b></span></li></ul>";
173 $ids = preg_replace('/[^0-9,]/','',$ids); // securite
174 $result = spip_query("SELECT * FROM spip_auteurs WHERE id_auteur IN ($ids) ORDER BY nom");
177 . _T('texte_plusieurs_articles', array('cherche_auteur' => $cherche_auteur))
179 . "<ul class='verdana1'>";
180 while ($row = spip_fetch_array($result)) {
181 $id_auteur = $row['id_auteur'];
182 $nom_auteur = $row['nom'];
183 $email_auteur = $row['email'];
184 $bio_auteur = $row['bio'];
186 $res .= "<li><b>".typo($nom_auteur)."</b>";
188 if ($email_auteur) $res .= " ($email_auteur)";
191 . ajax_action_auteur('editer_auteurs', "$id,$type,$id_auteur",$script_edit_objet,"id_{$type}=$id", array(_T('lien_ajouter_auteur')),$arg_ajax);
193 if (trim($bio_auteur)) {
194 $res .= "<br />".couper(propre($bio_auteur), 100)."\n";
203 // http://doc.spip.org/@afficher_auteurs_objet
204 function afficher_auteurs_objet($type, $id, $flag_editable, $cond_les_auteurs, $script_edit, $arg_ajax)
206 global $connect_statut, $options,$connect_id_auteur, $spip_display;
209 $les_auteurs = array();
210 if (!preg_match(',^[a-z]*$,',$type)) return $les_auteurs;
212 $result = determiner_auteurs_objet($type,$id,$cond_les_auteurs);
213 $cpt = spip_num_rows($result);
215 $tmp_var = "editer_auteurs-$id";
216 $nb_aff = floor(1.5 * _TRANCHES
);
217 if ($cpt > $nb_aff) {
219 $tranches = afficher_tranches_requete($cpt, $tmp_var, generer_url_ecrire('editer_auteurs',$arg_ajax), $nb_aff);
220 } else $tranches = '';
222 $deb_aff = _request($tmp_var);
223 $deb_aff = ($deb_aff !== NULL ?
intval($deb_aff) : 0);
225 $limit = (($deb_aff < 0) ?
'' : "$deb_aff, $nb_aff");
226 $result = determiner_auteurs_objet($type,$id,$cond_les_auteurs,$limit);
228 // charger ici meme si ps d'auteurs
229 // car inc_formater_auteur peut aussi redefinir determiner_non_auteurs qui sert plus loin
230 if (!$formater_auteur = charger_fonction("formater_auteur_$type", 'inc',true
))
231 $formater_auteur = charger_fonction('formater_auteur', 'inc');
233 if (!spip_num_rows($result)) return '';
237 while ($row = spip_fetch_array($result)) {
238 $id_auteur = $row['id_auteur'];
239 $vals = $formater_auteur($id_auteur);
241 if ($flag_editable AND ($connect_id_auteur != $id_auteur OR $connect_statut == '0minirezo') AND $options == 'avancees') {
242 $vals[] = ajax_action_auteur('editer_auteurs', "$id,$type,-$id_auteur", $script_edit, "id_{$type}=$id", array(_T('lien_retirer_auteur')." ". http_img_pack('croix-rouge.gif', "X", " class='puce' style='vertical-align: bottom;'")),$arg_ajax);
247 $largeurs = array('14', '', '', '', '', '');
248 $styles = array('arial11', 'arial2', 'arial11', 'arial11', 'arial11', 'arial1');
250 $t = afficher_liste($largeurs, $table, $styles);
251 if ($spip_display != 4)
253 . "<table width='100%' cellpadding='3' cellspacing='0' border='0'>"
256 return "<div class='liste'>$t</div>\n";
260 // http://doc.spip.org/@ajouter_auteurs_objet
261 function ajouter_auteurs_objet($type, $id, $cond_les_auteurs,$script_edit, $arg_ajax)
264 if (!$determiner_non_auteurs = charger_fonction('determiner_non_auteurs_'.$type,'inc',true
))
265 $determiner_non_auteurs = 'determiner_non_auteurs';
266 $query = $determiner_non_auteurs($type, $id, $cond_les_auteurs, "statut, nom");
267 if (!$num = spip_num_rows($query)) return '';
269 $js = "findObj_forcer('valider_ajouter_auteur').style.visibility='visible';";
271 $text = "<span class='verdana1'><b>"
272 . _T('titre_cadre_ajouter_auteur')
275 if ($num <= _SPIP_SELECT_MIN_AUTEURS
){
276 $sel = "$text<select name='nouv_auteur' size='1' style='width:150px;' class='fondl' onchange=\"$js\">" .
277 objet_auteur_select($query) .
279 $clic = _T('bouton_ajouter');
280 } else if ((_SPIP_AJAX
< 1) OR ($num >= _SPIP_SELECT_MAX_AUTEURS
)) {
281 $sel = "$text <input type='text' name='cherche_auteur' onclick=\"$js\" class='fondl' value='' size='20' />";
282 $clic = _T('bouton_chercher');
284 $sel = selecteur_auteur_ajax($type, $id, $js, $text);
285 $clic = _T('bouton_ajouter');
288 return ajax_action_post('editer_auteurs', "$id,$type", $script_edit, "id_{$type}=$id", $sel, $clic, "class='fondo visible_au_chargement' id='valider_ajouter_auteur'", "", $arg_ajax);
291 // http://doc.spip.org/@objet_auteur_select
292 function objet_auteur_select($result)
294 global $couleur_claire, $connect_statut ;
296 $statut_old = $premiere_old = $res = '';
298 while ($row = spip_fetch_array($result)) {
299 $id_auteur = $row["id_auteur"];
301 $email = $row["email"];
302 $statut = $row["statut"];
304 $statut=str_replace("0minirezo", _T('info_administrateurs'), $statut);
305 $statut=str_replace("1comite", _T('info_redacteurs'), $statut);
306 $statut=str_replace("6visiteur", _T('info_visiteurs'), $statut);
308 $premiere = strtoupper(substr(trim($nom), 0, 1));
310 if ($connect_statut != '0minirezo')
311 if ($p = strpos($email, '@'))
312 $email = substr($email, 0, $p).'@...';
314 $email = " ($email)";
316 if ($statut != $statut_old) {
317 $res .= "\n<option value=\"x\" />";
318 $res .= "\n<option value=\"x\" style='background-color: $couleur_claire;'> $statut</option>";
321 if ($premiere != $premiere_old AND ($statut != _T('info_administrateurs') OR !$premiere_old))
322 $res .= "\n<option value=\"x\" />";
324 $res .= "\n<option value=\"$id_auteur\"> " . supprimer_tags(couper(typo("$nom$email"), 40)) . '</option>';
325 $statut_old = $statut;
326 $premiere_old = $premiere;
331 // http://doc.spip.org/@selecteur_auteur_ajax
332 function selecteur_auteur_ajax($type, $id, $js, $text)
334 include_spip('inc/chercher_rubrique');
335 $url = generer_url_ecrire('selectionner_auteur',"id_article=$id_article");
337 return $text . construire_selecteur($url, $js, 'selection_auteur', 'nouv_auteur', ' type="hidden"');