[ Index ]
 

Code source de SPIP 1.9.2c

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/ecrire/inc/ -> editer_auteurs.php (source)

   1  <?php
   2  
   3  /***************************************************************************\
   4   *  SPIP, Systeme de publication pour l'internet                           *
   5   *                                                                         *
   6   *  Copyright (c) 2001-2007                                                *
   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', 10); // en dessous: balise Select
  20  define('_SPIP_SELECT_MAX_AUTEURS', 100); // 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      global $options;
  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");
  29      else 
  30          $arg_ajax.= "&titre=".urlencode($titre_boite);
  31  
  32  
  33      $cond_les_auteurs = "";
  34      $aff_les_auteurs = afficher_auteurs_objet($type, $id, $flag, $cond_les_auteurs, $script_edit_objet, $arg_ajax);
  35      
  36      if ($flag AND $options == 'avancees') {
  37          $futurs = ajouter_auteurs_objet($type, $id, $cond_les_auteurs,$script_edit_objet, $arg_ajax);
  38      } else $futurs = '';
  39  
  40      $ldap = isset($GLOBALS['meta']['ldap_statut_import']) ?
  41        $GLOBALS['meta']['ldap_statut_import'] : '';
  42  
  43      return editer_auteurs_objet($type, $id, $flag, $cherche_auteur, $ids, $aff_les_auteurs, $futurs, $ldap,$titre_boite,$script_edit_objet, $arg_ajax);
  44  }
  45  
  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)
  48  {
  49      global $spip_lang_left, $spip_lang_right, $options;
  50  
  51      $bouton_creer_auteur =  $GLOBALS['connect_toutes_rubriques'];
  52      $clic = _T('icone_creer_auteur');
  53  
  54  //
  55  // complement de action/editer_auteurs.php pour notifier la recherche d'auteur
  56  //
  57      if ($cherche_auteur) {
  58  
  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);
  62  
  63          if ($type=='article' && $bouton_creer_auteur) { // pas generique pour le moment
  64  
  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", '&'));
  69  
  70              $reponse .="<div style='width: 200px;'>"
  71              . icone_horizontale($clic, $legende, "redacteurs-24.gif", "creer.gif", false)
  72              . "</div> ";
  73  
  74              $bouton_creer_auteur = false;
  75          }
  76  
  77          $reponse .= fin_boite_info(true)
  78          . '</div>';
  79      } else $reponse ='';
  80  
  81      $reponse .= $les_auteurs;
  82  
  83  //
  84  // Ajouter un auteur
  85  //
  86  
  87      $res = '';
  88      if ($flag AND $options == 'avancees') {
  89  
  90          if ($type=='article' && $bouton_creer_auteur) { // pas generique pour le moment
  91  
  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", '&'));
  96  
  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)
 100              . "</div>\n";
 101          }
 102  
 103          $res = "<div style='float:$spip_lang_right; width:280px;position:relative;display:inline;'>"
 104          . $futurs
 105          ."</div>\n"
 106          . $res;
 107      }
 108  
 109      $bouton = (!$flag 
 110             ? ''
 111             : (($flag === 'ajax')
 112              ? bouton_block_visible("auteurs$type")
 113              : bouton_block_invisible("auteurs$type")))
 114      . $titre_boite;
 115  
 116      $res = '<div><div>&nbsp;</div>' // pour placer le gif patienteur
 117      . debut_cadre_enfonce("auteur-24.gif", true, "", $bouton)
 118      . $reponse
 119      .  ($flag === 'ajax' ?
 120          debut_block_visible("auteurs$type") :
 121          debut_block_invisible("auteurs$type"))
 122      . $res
 123      . fin_block()
 124      . fin_cadre_enfonce(true)
 125          . '</div>';
 126  
 127      return ajax_action_greffe("editer_auteurs-$id", $res);
 128  }
 129  
 130  // http://doc.spip.org/@determiner_auteurs_objet
 131  function determiner_auteurs_objet($type, $id, $cond='', $limit='')
 132  {
 133      $les_auteurs = array();
 134      if (!preg_match(',^[a-z]*$,',$type)) return $les_auteurs; 
 135  
 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": '')
 139      );
 140  
 141      return $result;
 142  }
 143  // http://doc.spip.org/@determiner_non_auteurs
 144  function determiner_non_auteurs($type, $id, $cond_les_auteurs, $order)
 145  {
 146      $cond = '';
 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'];
 151      }
 152      if (strlen($cond))
 153          $cond = "id_auteur NOT IN (" . substr($cond,1) . ') AND ';
 154  
 155      return spip_query("SELECT * FROM spip_auteurs WHERE $cond" . "statut!='5poubelle' AND statut!='6forum' AND statut!='nouveau' ORDER BY $order");
 156  }
 157  
 158  // http://doc.spip.org/@rechercher_auteurs_objet
 159  function rechercher_auteurs_objet($cherche_auteur, $ids, $type, $id, $script_edit_objet, $arg_ajax)
 160  {
 161      if (!$ids) {
 162          return "<b>"._T('texte_aucun_resultat_auteur', array('cherche_auteur' => $cherche_auteur)).".</b><br />";
 163      }
 164      elseif ($ids == -1) {
 165          return "<b>"._T('texte_trop_resultats_auteurs', array('cherche_auteur' => $cherche_auteur))."</b><br />";
 166      }
 167      elseif (preg_match('/^\d+$/',$ids)) {
 168  
 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>";
 171      }
 172      else {
 173          $ids = preg_replace('/[^0-9,]/','',$ids); // securite
 174          $result = spip_query("SELECT * FROM spip_auteurs WHERE id_auteur IN ($ids) ORDER BY nom");
 175  
 176          $res = "<b>"
 177          . _T('texte_plusieurs_articles', array('cherche_auteur' => $cherche_auteur))
 178          . "</b><br />"
 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'];
 185  
 186                  $res .= "<li><b>".typo($nom_auteur)."</b>";
 187  
 188                  if ($email_auteur) $res .= " ($email_auteur)";
 189  
 190                  $res .= " | "
 191                    .  ajax_action_auteur('editer_auteurs', "$id,$type,$id_auteur",$script_edit_objet,"id_{$type}=$id", array(_T('lien_ajouter_auteur')),$arg_ajax);
 192  
 193                  if (trim($bio_auteur)) {
 194                      $res .= "<br />".couper(propre($bio_auteur), 100)."\n";
 195                  }
 196                  $res .= "</li>\n";
 197              }
 198          $res .= "</ul>";
 199          return $res;
 200      }
 201  }
 202  
 203  // http://doc.spip.org/@afficher_auteurs_objet
 204  function afficher_auteurs_objet($type, $id, $flag_editable, $cond_les_auteurs, $script_edit, $arg_ajax)
 205  {
 206      global $connect_statut, $options,$connect_id_auteur, $spip_display;
 207      
 208      
 209      $les_auteurs = array();
 210      if (!preg_match(',^[a-z]*$,',$type)) return $les_auteurs; 
 211  
 212      $result = determiner_auteurs_objet($type,$id,$cond_les_auteurs);
 213      $cpt = spip_num_rows($result);
 214  
 215      $tmp_var = "editer_auteurs-$id";
 216      $nb_aff = floor(1.5 * _TRANCHES);
 217      if ($cpt > $nb_aff) {
 218          $nb_aff = _TRANCHES; 
 219          $tranches = afficher_tranches_requete($cpt, $tmp_var, generer_url_ecrire('editer_auteurs',$arg_ajax), $nb_aff);
 220      } else $tranches = '';
 221      
 222      $deb_aff = _request($tmp_var);
 223      $deb_aff = ($deb_aff !== NULL ? intval($deb_aff) : 0);
 224      
 225      $limit = (($deb_aff < 0) ? '' : "$deb_aff, $nb_aff");
 226      $result = determiner_auteurs_objet($type,$id,$cond_les_auteurs,$limit);
 227  
 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');
 232  
 233      if (!spip_num_rows($result)) return '';
 234  
 235      $table = array();
 236  
 237      while ($row = spip_fetch_array($result)) {
 238          $id_auteur = $row['id_auteur'];
 239          $vals = $formater_auteur($id_auteur);
 240  
 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')."&nbsp;". http_img_pack('croix-rouge.gif', "X", " class='puce' style='vertical-align: bottom;'")),$arg_ajax);
 243          } else  $vals[] = "";
 244          $table[] = $vals;
 245      }
 246      
 247      $largeurs = array('14', '', '', '', '', '');
 248      $styles = array('arial11', 'arial2', 'arial11', 'arial11', 'arial11', 'arial1');
 249  
 250      $t = afficher_liste($largeurs, $table, $styles);
 251      if ($spip_display != 4)
 252        $t = $tranches
 253            . "<table width='100%' cellpadding='3' cellspacing='0' border='0'>"
 254          . $t
 255          . "</table>";
 256      return "<div class='liste'>$t</div>\n";
 257  }
 258  
 259  
 260  // http://doc.spip.org/@ajouter_auteurs_objet
 261  function ajouter_auteurs_objet($type, $id, $cond_les_auteurs,$script_edit, $arg_ajax)
 262  {
 263  
 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 '';
 268  
 269      $js = "findObj_forcer('valider_ajouter_auteur').style.visibility='visible';";
 270  
 271      $text = "<span class='verdana1'><b>"
 272      . _T('titre_cadre_ajouter_auteur')
 273      . "</b></span>\n";
 274  
 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) .
 278             "</select>";
 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');
 283      } else {
 284          $sel = selecteur_auteur_ajax($type, $id, $js, $text);
 285          $clic = _T('bouton_ajouter');
 286      }
 287  
 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);
 289  }
 290  
 291  // http://doc.spip.org/@objet_auteur_select
 292  function objet_auteur_select($result)
 293  {
 294      global $couleur_claire, $connect_statut ;
 295  
 296      $statut_old = $premiere_old = $res = '';
 297  
 298      while ($row = spip_fetch_array($result)) {
 299          $id_auteur = $row["id_auteur"];
 300          $nom = $row["nom"];
 301          $email = $row["email"];
 302          $statut = $row["statut"];
 303  
 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);
 307                  
 308          $premiere = strtoupper(substr(trim($nom), 0, 1));
 309  
 310          if ($connect_statut != '0minirezo')
 311              if ($p = strpos($email, '@'))
 312                    $email = substr($email, 0, $p).'@...';
 313          if ($email)
 314              $email = " ($email)";
 315  
 316          if ($statut != $statut_old) {
 317              $res .= "\n<option value=\"x\" />";
 318              $res .= "\n<option value=\"x\" style='background-color: $couleur_claire;'> $statut</option>";
 319          }
 320  
 321          if ($premiere != $premiere_old AND ($statut != _T('info_administrateurs') OR !$premiere_old))
 322              $res .= "\n<option value=\"x\" />";
 323                  
 324          $res .= "\n<option value=\"$id_auteur\">&nbsp;&nbsp;&nbsp;&nbsp;" . supprimer_tags(couper(typo("$nom$email"), 40)) . '</option>';
 325          $statut_old = $statut;
 326          $premiere_old = $premiere;
 327      }
 328      return $res;
 329  }
 330  
 331  // http://doc.spip.org/@selecteur_auteur_ajax
 332  function selecteur_auteur_ajax($type, $id, $js, $text)
 333  {
 334      include_spip('inc/chercher_rubrique');
 335      $url = generer_url_ecrire('selectionner_auteur',"id_article=$id_article");
 336  
 337      return $text . construire_selecteur($url, $js, 'selection_auteur', 'nouv_auteur', ' type="hidden"');
 338  }
 339  ?>


Généré le : Wed Nov 21 10:20:27 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics